Combination lock counter The scene is:
Peter is at the gym with his buddy Brian when Brian suddenly is in dire need of his inhaler. Brian manages to tell Peter the code to his combination lock before he collapses on the floor.
The moment Peter gets to Brian's locker and sees what the indicator is pointing at, Stewie ambushes him and sprays a full can of pepper spray in his face, thus blinding Peter.
Peter must now try to open the lock without looking at it. He starts turning the dial to the right, counting the numbers while he passes them. He then, at the correct number starts turning the dial to the left, still counting, and finally turns it to the right until the lock opens.

The challenge:
Write a function/program that takes two inputs, the combination from Brian, and the indicator position. Output the numbers Peter has to count.
Rules:

The combination and the indicator position must be separate arguments.
The input can be either from command prompt or as function arguments.
The output must be printed to the screen / otherwise displayed (not to file)
Assume that the starting position is not the same as the first number, and that all three numbers in the combination are unique
It's the lock shown in the picture below, with possible numbers: 0-39.

Instructions:
To open the lock below, you need to follow a set of instructions:

You must know your code. Assume it's (38, 16, 22) for now.
Turn the dial 3 times to the right (passing the starting number three times), then stop when the first number (38) aligns with the indicator
Turn the dial 1 full turn to the left, passing
the first number, and stop when the second number (16) lines
up with the indicator.
Turn the dial to the right and stop when the
third number (22) lines up with the indicator
Pull the lock down


Example:
Input
38 16 22
33  

Output
33  32  31  30  29  28  27  26  25  24  23  22  21  20  19  18  17  16  15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0  39  38  37  36  35  34  33  32  31  30  29  28  27  26  25  24  23  22  21  20  19  18  17  16  15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0  39  38  37  36  35  34  33  32  31  30  29  28  27  26  25  24  23  22  21  20  19  18  17  16  15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0  39  38  37  36  35  34  33  32  31  30  29  28  27  26  25  24  23  22  21  20  19  18  17  16  15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0  39  38  39   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0  39  38  37  36  35  34  33  32  31  30  29  28  27  26  25  24  23  22

Standard code golf rules apply.
Solutions that are posted later can still win if they're shorter than Dennis' answer.
CJam, 52 39 bytes

q~[3X0].{@40,m&lt;1$({(+W%}&amp;:T*T@#)T&lt;)}e_p


Try it online in the CJam interpreter.

How it works

q~      e# Read and evaluate all input. This pushes the initial position
        e# as an integer and the combination as an array.
[3X0]   e# Push [3 1 0]. This encodes the respective numbers of full turns
.{      e# For each number in the combination (N) and the corresponding 
        e# number of full turns (F):
  @     e#   Rotate the initial position on top of the stack.
  40,m&lt; e#   Push [0 ... 39] and rotate it that many units to the left.
        e#   For position P, this pushes [P P+1 ... 39 0 ... P-2 P-1].
  1$(   e#   Copy F and subtract 1.
  {     e#   If the result is non-zero:
    (+  e#     Rotate the array of length 40 one unit to the left.
    W%  e#     Reverse it.
  }&amp;    e#   For position P, this pushes [P P-1 ... 0 39 ... P+2 P+1].
  :T*   e#   Save in T and repeat the array F.
  T@    e#   Push T. Rotate N on top of the stack.
  #)    e#   Find the index of N in T and add 1 to it.
  T&lt;    e#   Keep that many elements from the beginning of T.
  )     e#   Pop the last element of the result (N).
}       e# N is the new initial position.
e_p     e# Flatten the resulting array and print it.