#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 pop(int *, int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ push(int, int *, int *);
int main(void) {
  int a[20];
  int top = -1;
  int num = 123;
  int rev = 0;
  int i = 1;
  while (num != 0) {
    push(num % 10, a, &top);
    num = num / 10;
  }
  while (top != -1) {
    rev = rev + pop(a, &top) * i;
    i = i * 10;
  }
  printf("%d\n", rev);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x64(%rbp)
movl   $0x7b,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x1,-0x70(%rbp)
cmpl   $0x0,-0x68(%rbp)
je     1195 <main+0x65>
mov    -0x68(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
lea    -0x60(%rbp),%rsi
lea    -0x64(%rbp),%rdx
call   1050 <push@plt>
mov    -0x68(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x68(%rbp)
jmp    115e <main+0x2e>
jmp    119a <main+0x6a>
cmpl   $0xffffffff,-0x64(%rbp)
je     11d1 <main+0xa1>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x74(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x64(%rbp),%rsi
call   1040 <pop@plt>
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
imul   -0x70(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x6c(%rbp)
imul   $0xa,-0x70(%rbp),%eax
mov    %eax,-0x70(%rbp)
jmp    119a <main+0x6a>
mov    -0x6c(%rbp),%esi
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0x10(%rsp),%rbp
lea    0xc(%rsp),%r14
mov    $0x3,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <push@plt>
mov    $0x2,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <push@plt>
mov    $0x1,%ebx
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <push@plt>
cmpl   $0xffffffff,0xc(%rsp)
je     11be <main+0x8e>
xor    %ebp,%ebp
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <pop@plt>
imul   %ebx,%eax
add    %eax,%ebp
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
cmpl   $0xffffffff,0xc(%rsp)
jne    11a0 <main+0x70>
jmp    11c0 <main+0x90>
xor    %ebp,%ebp
lea    0xe39(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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