#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*/ printf(char *, int, int);
void reverse(int input) {
  int rightdigit;
  int sum = 0;
  while (input > 0) {
    printf("%d=> %d\n", input, sum);
    rightdigit = input % 10;
    sum = sum * 10 + rightdigit;
    input = input / 10;
  }
  printf("%d=> %d\n", input, sum);
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1169 <reverse+0x59>
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
imul   $0xa,-0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1122 <reverse+0x12>
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%esi
xor    %ebx,%ebx
test   %edi,%edi
jle    115d <reverse+0x4d>
lea    0xeda(%rip),%r14
mov    $0xcccccccd,%r15d
mov    %esi,%ebp
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
lea    (%rbx,%rbx,4),%eax
mov    %ebp,%esi
imul   %r15,%rsi
shr    $0x23,%rsi
lea    (%rsi,%rsi,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %ebp,%edx
sub    %ecx,%edx
lea    (%rdx,%rax,2),%ebx
cmp    $0x9,%ebp
mov    %esi,%ebp
ja     1130 <reverse+0x20>
lea    0xe9c(%rip),%rdi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [9 x i8] c"%d=> %d\0A\00"
define void @reverse(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %12
3: ; preds = %1, %3
%4 = phi i32 [ %9, %3 ], [ 0, %1 ]
%5 = phi i32 [ %10, %3 ], [ %0, %1 ]
%6 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %4)
%7 = urem i32 %5, 10
%8 = mul nsw i32 %4, 10
%9 = add nsw i32 %8, %7
%10 = udiv i32 %5, 10
%11 = icmp ult i32 %5, 10
br i1 %11, label %12, label %3
12: ; preds = %3, %1
%13 = phi i32 [ %0, %1 ], [ %10, %3 ]
%14 = phi i32 [ 0, %1 ], [ %9, %3 ]
%15 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
ret void
}