#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 /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *grayCode(int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: ./test n\n");
    exit(-1);
  }
  int i, count;
  int *list = grayCode(atoi(argv[1]), &count);
  for (i = 0; i < count; i++) {
    printf("%d ", list[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118f <main+0x3f>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1050 <grayCode@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e5 <main+0x95>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <main+0x62>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11d2 <main+0x72>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
call   1060 <grayCode@plt>
cmpl   $0x0,0xc(%rsp)
jle    11bc <main+0x5c>
mov    %rax,%r15
lea    0xe7d(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11a0 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Usage: ./test n\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
%20 = call i32* @grayCode(i32 %19, i32* %7)
store i32* %20, i32** %8
store i32 0, i32* %6
br label %21
21: ; preds = %32, %15
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i32*, i32** %8
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %25
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %21
35: ; preds = %21
%36 = 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 = [17 x i8] c"Usage: ./test n\0A\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = bitcast i32* %3 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = call i32* @grayCode(i32 %13, i32* %3)
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %9, %17
%18 = phi i64 [ %22, %17 ], [ 0, %9 ]
%19 = getelementptr inbounds i32, i32* %14, i64 %18
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %18, 1
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %17, label %26
26: ; preds = %17, %9
%27 = call i32 @putchar(i32 10)
ret i32 0
}