#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rotate(int *, int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: ./test k n1 n2...\n");
    exit(-1);
  }
  int k = atoi(argv[1]);
  int i, count = argc - 2;
  int *nums = malloc(count * sizeof(int));
  for (i = 0; i < count; i++) {
    nums[i] = atoi(argv[i + 2]);
  }
  rotate(nums, count, k);
  for (i = 0; i < count; i++) {
    printf("%d ", nums[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119f <main+0x3f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120f <main+0xaf>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d2 <main+0x72>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <rotate@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1258 <main+0xf8>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1225 <main+0xc5>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1243 <main+0xd3>
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
lea    -0x2(%r14),%ebx
lea    -0x8(,%r14,4),%edi
ff
call   1070 <malloc@plt>
mov    %rax,%r13
cmp    $0x2,%r14d
jne    11bd <main+0x4d>
mov    %r13,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <rotate@plt>
jmp    1228 <main+0xb8>
mov    %ebp,0x4(%rsp)
mov    %ebx,%ebp
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%r15,%r12,8),%rdi
call   1080 <atoi@plt>
mov    %eax,0x0(%r13,%r12,4)
add    $0x1,%r12
cmp    %r12,%rbp
jne    11d0 <main+0x60>
mov    %r13,%rdi
mov    %ebx,%esi
mov    0x4(%rsp),%edx
call   1060 <rotate@plt>
cmp    $0x3,%r14d
jl     1228 <main+0xb8>
lea    0xe17(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1210 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: ./test k n1 n2...\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 2
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 4
%26 = trunc i64 %25 to i32
%27 = call i32* @malloc(i32 %26)
store i32* %27, i32** %9
store i32 0, i32* %7
br label %28
28: ; preds = %44, %16
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = load i32*, i32** %9
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
br label %44
44: ; preds = %32
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %28
47: ; preds = %28
%48 = load i32*, i32** %9
%49 = load i32, i32* %8
%50 = load i32, i32* %6
%51 = call i32 @rotate(i32* %48, i32 %49, i32 %50)
store i32 0, i32* %7
br label %52
52: ; preds = %63, %47
%53 = load i32, i32* %7
%54 = load i32, i32* %8
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %66
56: ; preds = %52
%57 = load i32*, i32** %9
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %56
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %52
66: ; preds = %52
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: ./test k n1 n2...\0A\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = add nsw i32 %0, -2
%13 = shl i32 %12, 2
%14 = tail call i32* @malloc(i32 %13)
%15 = icmp eq i32 %0, 2
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 @rotate(i32* %14, i32 %12, i32 %11)
br label %41
18: ; preds = %8
%19 = zext i32 %12 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %27, %20 ]
%22 = add nuw nsw i64 %21, 2
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = getelementptr inbounds i32, i32* %14, i64 %21
store i32 %25, i32* %26
%27 = add nuw nsw i64 %21, 1
%28 = icmp eq i64 %27, %19
br i1 %28, label %29, label %20
29: ; preds = %20
%30 = tail call i32 @rotate(i32* %14, i32 %12, i32 %11)
%31 = icmp sgt i32 %0, 2
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = zext i32 %12 to i64
br label %34
34: ; preds = %32, %34
%35 = phi i64 [ 0, %32 ], [ %39, %34 ]
%36 = getelementptr inbounds i32, i32* %14, i64 %35
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = add nuw nsw i64 %35, 1
%40 = icmp eq i64 %39, %33
br i1 %40, label %41, label %34
41: ; preds = %34, %16, %29
%42 = tail call i32 @putchar(i32 10)
ret i32 0
}