#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int uint32_t;
struct TYPE_3__ {
  int quot;
  scalar_t__ rem;
};
typedef TYPE_1__ ldiv_t;

/* Variables and functions */
TYPE_1__ ldiv(int, int);
uint32_t reverse(uint32_t const n) {
  ldiv_t division;
  uint32_t result = 0;
  uint32_t workspace = n;
  do {
    division = ldiv(workspace, 10);
    result = 10 * result + (uint32_t)division.rem;
  } while (0 < (workspace = division.quot));
  return result;
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    $0xa,%esi
call   1030 <ldiv@plt>
mov    %eax,-0x30(%rbp)
mov    %rdx,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
imul   $0xa,-0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
mov    %ecx,-0x20(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jl     1128 <reverse+0x18>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbx
mov    %edi,%eax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%edi
mov    $0xa,%esi
call   1030 <ldiv@plt>
lea    (%rbx,%rbx,4),%ecx
lea    (%rdx,%rcx,2),%ebx
test   %eax,%eax
jg     1120 <reverse+0x10>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i64 }
define i32 @reverse(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.TYPE_3__
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.TYPE_3__
store i32 %0, i32* %2
store i32 0, i32* %4
%7 = load i32, i32* %2
store i32 %7, i32* %5
br label %8
8: ; preds = %24, %1
%9 = load i32, i32* %5
%10 = call { i32, i64 } @ldiv(i32 %9, i32 10)
%11 = bitcast %struct.TYPE_3__* %6 to { i32, i64 }*
%12 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %11, i32 0, i32 0
%13 = extractvalue { i32, i64 } %10, 0
store i32 %13, i32* %12
%14 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %11, i32 0, i32 1
%15 = extractvalue { i32, i64 } %10, 1
store i64 %15, i64* %14
%16 = bitcast %struct.TYPE_3__* %3 to i8*
%17 = bitcast %struct.TYPE_3__* %6 to i8*
%18 = load i32, i32* %4
%19 = mul nsw i32 10, %18
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 1
%21 = load i64, i64* %20
%22 = trunc i64 %21 to i32
%23 = add nsw i32 %19, %22
store i32 %23, i32* %4
br label %24
24: ; preds = %8
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 0
%26 = load i32, i32* %25
store i32 %26, i32* %5
%27 = icmp slt i32 0, %26
br i1 %27, label %8, label %28
28: ; preds = %24
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @reverse(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ %0, %1 ], [ %6, %2 ]
%4 = phi i32 [ 0, %1 ], [ %10, %2 ]
%5 = tail call { i32, i64 } @ldiv(i32 %3, i32 10)
%6 = extractvalue { i32, i64 } %5, 0
%7 = extractvalue { i32, i64 } %5, 1
%8 = mul nsw i32 %4, 10
%9 = trunc i64 %7 to i32
%10 = add nsw i32 %8, %9
%11 = icmp sgt i32 %6, 0
br i1 %11, label %2, label %12
12: ; preds = %2
ret i32 %10
}