#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int num = 40532;
  unsigned char buf[16];
  unsigned char *p;
  if (argc == 2) {
    num = atoi(argv[1]);
  }
  printf("%d\n", num);
  memset(buf, 0, sizeof(buf));
  p = &buf[0];
  if (num < 0) {
    *p++ = '-';
    num *= -1;
  }
  int i = num;
  while (i) {
    i = i / 10;
    p++;
  }
  do {
    *--p = num % 10 + '0';
    num = num / 10;
  } while (num);
  printf("%s\n", buf);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x9e54,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1167 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b3 <main+0x83>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x2d,(%rax)
imul   $0xffffffff,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11e2 <main+0xb2>
mov    -0x3c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11b9 <main+0x89>
jmp    11e7 <main+0xb7>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11e7 <main+0xb7>
lea    -0x30(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x9e54,%r14d
cmp    $0x2,%edi
jne    115f <main+0x1f>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
lea    0xe9a(%rip),%rdi
xor    %ebp,%ebp
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
test   %r14d,%r14d
js     118d <main+0x4d>
jne    1199 <main+0x59>
jmp    11c6 <main+0x86>
lea    0x1(%rsp),%rbx
movb   $0x2d,(%rsp)
neg    %r14d
mov    %r14d,%eax
nopl   0x0(%rax)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    $0x1,%rbx
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     11a0 <main+0x60>
mov    %r14d,%ebp
add    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
movslq %ebp,%rax
imul   $0x66666667,%rax,%rbp
mov    %rbp,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rbp
add    %ecx,%ebp
lea    0x0(%rbp,%rbp,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
add    $0x30,%dl
mov    %dl,(%rbx)
add    $0x9,%eax
add    $0xffffffffffffffff,%rbx
cmp    $0x12,%eax
ja     11d0 <main+0x90>
mov    %rsp,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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