#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*/ itoa(int, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void reverse(int number) {
  char output[100];
  char numberString[100];
  bool endsWithZero = false;
  int reversed = number % 10;
  number /= 10;
  if (reversed == 0) {
    endsWithZero = true;
  }
  while (number > 0) {
    reversed *= 10;
    reversed += number % 10;
    number /= 10;
  }
  itoa(reversed, numberString, 10);
  if (endsWithZero) {
    strcpy(output, "0");
    strcat(output, numberString);
  } else {
    strcpy(output, numberString);
  }
  printf("%s\n", output);
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xe4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xe8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0xe8(%rbp)
jne    118e <reverse+0x4e>
movl   $0x1,-0xe4(%rbp)
jmp    1193 <reverse+0x53>
cmpl   $0x0,-0x4(%rbp)
jle    11d4 <reverse+0x94>
imul   $0xa,-0xe8(%rbp),%eax
mov    %eax,-0xe8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0xe8(%rbp),%edx
mov    %edx,-0xe8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1193 <reverse+0x53>
mov    -0xe8(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xa,%edx
call   1060 <itoa@plt>
cmpl   $0x0,-0xe4(%rbp)
je     121d <reverse+0xdd>
lea    -0x70(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1050 <strcat@plt>
jmp    122d <reverse+0xed>
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rsi
lea    0xdca(%rip),%rdi
call   1040 <printf@plt>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbp
push   %rbx
sub    $0xd8,%rsp
movslq %edi,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %ecx,%ebp
sub    %eax,%ebp
mov    %ebp,%eax
cmp    $0xa,%ecx
jl     11c0 <reverse+0x80>
mov    %ebp,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %edi,%rcx
imul   $0x66666667,%rcx,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rax,%rax,4),%eax
movslq %edi,%rdx
imul   $0x66666667,%rdx,%rsi
mov    %rsi,%rbx
shr    $0x3f,%rbx
sar    $0x22,%rsi
add    %ebx,%esi
add    %esi,%esi
lea    (%rsi,%rsi,4),%esi
sub    %esi,%edx
lea    (%rdx,%rax,2),%eax
cmp    $0x63,%ecx
jg     1180 <reverse+0x40>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1060 <itoa@plt>
test   %ebp,%ebp
je     11e2 <reverse+0xa2>
lea    0x70(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <strcpy@plt>
jmp    1201 <reverse+0xc1>
lea    0xe17(%rip),%rsi
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
lea    0xdfa(%rip),%rdi
lea    0x70(%rsp),%rsi
call   1040 <printf@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @reverse(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
%7 = load i32, i32* %2
%8 = srem i32 %7, 10
store i32 %8, i32* %6
%9 = load i32, i32* %2
%10 = sdiv i32 %9, 10
store i32 %10, i32* %2
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 1, i32* %5
br label %14
14: ; preds = %13, %1
br label %15
15: ; preds = %18, %14
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i32, i32* %6
%20 = mul nsw i32 %19, 10
store i32 %20, i32* %6
%21 = load i32, i32* %2
%22 = srem i32 %21, 10
%23 = load i32, i32* %6
%24 = add nsw i32 %23, %22
store i32 %24, i32* %6
%25 = load i32, i32* %2
%26 = sdiv i32 %25, 10
store i32 %26, i32* %2
br label %15
27: ; preds = %15
%28 = load i32, i32* %6
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%30 = call i32 @itoa(i32 %28, i8* %29, i32 10)
%31 = load i32, i32* %5
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %27
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%38 = call i32 @strcat(i8* %36, i8* %37)
br label %43
39: ; preds = %27
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%42 = call i32 @strcpy(i8* %40, i8* %41)
br label %43
43: ; preds = %39, %33
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %44)
ret void
}

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