#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 ireverse(int value) {
  char str[12] = {'\0'};
  char *ptr = str;
  int tmp;
  while (value) {
    tmp = value % 10;
    *ptr++ = tmp + '0';
    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   1030 <memset@plt>
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1187 <ireverse+0x67>
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    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1143 <ireverse+0x23>
lea    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ireverse>:
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
test   %edi,%edi
je     1164 <ireverse+0x54>
lea    0x8(%rsp),%rax
xchg   %ax,%ax
movslq %edi,%rcx
imul   $0x66666667,%rcx,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rdi,%rdi,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0x30,%sil
mov    %sil,(%rax)
add    $0x1,%rax
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1130 <ireverse+0x20>
lea    0x8(%rsp),%rdi
call   1030 <atoi@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
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 %21
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* %2
%20 = sdiv i32 %19, 10
store i32 %20, i32* %2
br label %8
21: ; preds = %8
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%23 = call i32 @atoi(i8* %22)
ret i32 %23
}

LLVM IR (-O2):
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 %15, label %5
5: ; preds = %1, %5
%6 = phi i32 [ %12, %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 = sdiv i32 %6, 10
%13 = add i32 %6, 9
%14 = icmp ult i32 %13, 19
br i1 %14, label %15, label %5
15: ; preds = %5, %1
%16 = call i32 @atoi(i8* %3)
ret i32 %16
}