#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 *init_wheel(int, int *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int len = 3;
  if (argc > 1)
    len = atoi(argv[1]);
  int wheel_len = 0;
  int *wheel = init_wheel(len, &wheel_len);
  if (wheel == NULL) {
    printf("This should never happen.");
  }
  printf("Length: %d\n\n", wheel_len);
  int i;
  for (i = 0; i < wheel_len; i++) {
    printf("%d", wheel[i]);
    if (i != wheel_len - 1)
      printf(", ");
    if (i % 16 == 15)
      printf("\n");
  }
  printf("\n\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)
movl   $0x3,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1167 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <init_wheel@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1197 <main+0x67>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1228 <main+0xf8>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     11f3 <main+0xc3>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    1215 <main+0xe5>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121a <main+0xea>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11af <main+0x7f>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%eax
mov    $0x3,%edi
cmp    $0x2,%eax
jl     116f <main+0x1f>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
call   1060 <init_wheel@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1197 <main+0x47>
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1216 <main+0xc6>
lea    0xe70(%rip),%r14
lea    0xe6c(%rip),%r15
xor    %ebx,%ebx
jmp    11de <main+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jge    1216 <main+0xc6>
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    %rax,%rbx
je     1202 <main+0xb2>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
not    %eax
test   $0xf,%al
jne    11d0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0x80>
lea    0xe08(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"This should never happen.\00"
@.str.1 = [13 x i8] c"Length: %d\0A\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c", \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [3 x i8] c"\0A\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
store i32 3, i32* %6
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
br label %17
17: ; preds = %12, %2
store i32 0, i32* %7
%18 = load i32, i32* %6
%19 = call i32* @init_wheel(i32 %18, i32* %7)
store i32* %19, i32** %8
%20 = load i32*, i32** %8
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = load i32, i32* %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 0, i32* %9
br label %27
27: ; preds = %51, %24
%28 = load i32, i32* %9
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %54
31: ; preds = %27
%32 = load i32*, i32** %8
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %9
%39 = load i32, i32* %7
%40 = sub nsw i32 %39, 1
%41 = icmp ne i32 %38, %40
br i1 %41, label %42, label %44
42: ; preds = %31
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %31
%45 = load i32, i32* %9
%46 = srem i32 %45, 16
%47 = icmp eq i32 %46, 15
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
br label %51
51: ; preds = %50
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %27
54: ; preds = %27
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"This should never happen.\00"
@.str.1 = [13 x i8] c"Length: %d\0A\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c", \00"
@str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
br label %9
9: ; preds = %5, %2
%10 = phi i32 [ %8, %5 ], [ 3, %2 ]
%11 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%12 = call i32* @init_wheel(i32 %10, i32* %3)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = load i32, i32* %3
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %42
21: ; preds = %16, %37
%22 = phi i64 [ %38, %37 ], [ 0, %16 ]
%23 = getelementptr inbounds i32, i32* %12, i64 %22
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = add nsw i32 %26, -1
%28 = zext i32 %27 to i64
%29 = icmp eq i64 %22, %28
br i1 %29, label %32, label %30
30: ; preds = %21
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %21
%33 = and i64 %22, 15
%34 = icmp eq i64 %33, 15
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @putchar(i32 10)
br label %37
37: ; preds = %32, %35
%38 = add nuw nsw i64 %22, 1
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %21, label %42
42: ; preds = %37, %16
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}