#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
main() {
  int num, rev = 0;
  int valid_input = 0;
  char inbuf[133];
  while (valid_input < 1) {
    printf("Enter an integer: ");
    gets(inbuf);
    valid_input = sscanf(inbuf, "%d", &num);
  }
  while (num != 0) {
    rev *= 10;
    rev += num % 10;
    num /= 10;
  }
  printf("Reverse number is %d\n", rev);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jge    1193 <main+0x63>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <gets@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe91(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x10(%rbp)
jmp    1150 <main+0x20>
jmp    1198 <main+0x68>
cmpl   $0x0,-0x8(%rbp)
je     11cd <main+0x9d>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0xc(%rbp),%edx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1198 <main+0x68>
mov    -0xc(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xebb(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xec2(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <gets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
test   %eax,%eax
jle    1160 <main+0x30>
mov    0xc(%rsp),%eax
xor    %esi,%esi
test   %eax,%eax
je     11c3 <main+0x93>
xchg   %ax,%ax
lea    (%rsi,%rsi,4),%ecx
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rax
add    %esi,%eax
lea    (%rax,%rax,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %edx,%edi
sub    %esi,%edi
lea    (%rdi,%rcx,2),%esi
add    $0x9,%edx
cmp    $0x12,%edx
ja     1190 <main+0x60>
mov    %eax,0xc(%rsp)
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter an integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"Reverse number is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [133 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %9, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [133 x i8], [133 x i8]* %5, i64 0, i64 0
%12 = call i32 @gets(i8* %11)
%13 = getelementptr inbounds [133 x i8], [133 x i8]* %5, i64 0, i64 0
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 %14, i32* %4
br label %6
15: ; preds = %6
br label %16
16: ; preds = %19, %15
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load i32, i32* %3
%21 = mul nsw i32 %20, 10
store i32 %21, i32* %3
%22 = load i32, i32* %2
%23 = srem i32 %22, 10
%24 = load i32, i32* %3
%25 = add nsw i32 %24, %23
store i32 %25, i32* %3
%26 = load i32, i32* %2
%27 = sdiv i32 %26, 10
store i32 %27, i32* %2
br label %16
28: ; preds = %16
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter an integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"Reverse number is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [133 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [133 x i8], [133 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %0, %5
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @gets(i8* %4)
%8 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = icmp slt i32 %8, 1
br i1 %9, label %5, label %10
10: ; preds = %5
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %10, %13
%14 = phi i32 [ %18, %13 ], [ 0, %10 ]
%15 = phi i32 [ %19, %13 ], [ %11, %10 ]
%16 = mul nsw i32 %14, 10
%17 = srem i32 %15, 10
%18 = add nsw i32 %16, %17
%19 = sdiv i32 %15, 10
%20 = add i32 %15, 9
%21 = icmp ult i32 %20, 19
br i1 %21, label %22, label %13
22: ; preds = %13
store i32 %19, i32* %1
br label %23
23: ; preds = %22, %10
%24 = phi i32 [ %18, %22 ], [ 0, %10 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %24)
ret i32 0
}