#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*/ printf(char *, int);
int ireverse(int value) {
  char str[12] = {'\0'};
  char *ptr = str;
  int tmp;
  while (value) {
    tmp = value % 10;
    *ptr++ = tmp + '0';
    printf("tmp = %d\n", tmp);
    value /= 10;
  }
  return atoi(str);
}


x86 assembly (clang, -O0):
<ireverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11a6 <ireverse+0x76>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%esi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1153 <ireverse+0x23>
lea    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ireverse>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
test   %edi,%edi
je     118e <ireverse+0x6e>
mov    %edi,%ebx
lea    0x8(%rsp),%r15
lea    0xeb2(%rip),%r14
xchg   %ax,%ax
movslq %ebx,%r12
imul   $0x66666667,%r12,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %r12d,%esi
sub    %eax,%esi
lea    0x30(%rsi),%eax
mov    %al,(%r15)
add    $0x1,%r15
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x9,%r12d
cmp    $0x12,%r12d
ja     1150 <ireverse+0x30>
lea    0x8(%rsp),%rdi
call   1040 <atoi@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"tmp = %d\0A\00"
define i32 @ireverse(i32 %0) {
%2 = alloca i32
%3 = alloca [12 x i8]
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = bitcast [12 x i8]* %3 to i8*
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
store i8* %7, i8** %4
br label %8
8: ; preds = %11, %1
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i32, i32* %2
%13 = srem i32 %12, 10
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 48
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
store i8 %16, i8* %17
%19 = load i32, i32* %5
%20 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %2
%22 = sdiv i32 %21, 10
store i32 %22, i32* %2
br label %8
23: ; preds = %8
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%25 = call i32 @atoi(i8* %24)
ret i32 %25
}

LLVM IR (-O2):
@.str = [10 x i8] c"tmp = %d\0A\00"
define i32 @ireverse(i32 %0) {
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32 %0, 0
br i1 %4, label %16, label %5
5: ; preds = %1, %5
%6 = phi i32 [ %13, %5 ], [ %0, %1 ]
%7 = phi i8* [ %11, %5 ], [ %3, %1 ]
%8 = srem i32 %6, 10
%9 = trunc i32 %8 to i8
%10 = add nsw i8 %9, 48
%11 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %10, i8* %7
%12 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
%13 = sdiv i32 %6, 10
%14 = add i32 %6, 9
%15 = icmp ult i32 %14, 19
br i1 %15, label %16, label %5
16: ; preds = %5, %1
%17 = call i32 @atoi(i8* %3)
ret i32 %17
}