#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 */
unsigned int integer_length(int);
void *render_byte(int, void *);
void *render_integer(int x, void *dest) {
  unsigned i, int_len = integer_length(x);
  for (i = int_len; i >= 1; i--)
    dest = render_byte((x >> (8 * (i - 1))) & 0xFF, dest);
  return dest;
}


x86 assembly (clang, -O0):
<render_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <integer_length@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jb     1179 <render_integer+0x59>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
shl    $0x3,%ecx
sar    %cl,%edi
and    $0xff,%edi
mov    -0x10(%rbp),%rsi
call   1030 <render_byte@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1140 <render_integer+0x20>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<render_integer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
call   1040 <integer_length@plt>
test   %eax,%eax
je     115d <render_integer+0x3d>
mov    %eax,%ebp
lea    -0x8(,%rbp,8),%ebx
nop
mov    %r14d,%eax
mov    %ebx,%ecx
sar    %cl,%eax
movzbl %al,%edi
mov    %r15,%rsi
call   1030 <render_byte@plt>
mov    %rax,%r15
add    $0xfffffff8,%ebx
add    $0xffffffff,%ebp
jne    1140 <render_integer+0x20>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @render_integer(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* %3
%8 = call i32 @integer_length(i32 %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
store i32 %9, i32* %5
br label %10
10: ; preds = %22, %2
%11 = load i32, i32* %5
%12 = icmp uge i32 %11, 1
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load i32, i32* %3
%15 = load i32, i32* %5
%16 = sub i32 %15, 1
%17 = mul i32 8, %16
%18 = ashr i32 %14, %17
%19 = and i32 %18, 255
%20 = load i8*, i8** %4
%21 = call i8* @render_byte(i32 %19, i8* %20)
store i8* %21, i8** %4
br label %22
22: ; preds = %13
%23 = load i32, i32* %5
%24 = add i32 %23, -1
store i32 %24, i32* %5
br label %10
25: ; preds = %10
%26 = load i8*, i8** %4
ret i8* %26
}

LLVM IR (-O2):
define i8* @render_integer(i32 %0, i8* %1) {
%3 = tail call i32 @integer_length(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %2, %5
%6 = phi i8* [ %12, %5 ], [ %1, %2 ]
%7 = phi i32 [ %13, %5 ], [ %3, %2 ]
%8 = shl i32 %7, 3
%9 = add i32 %8, -8
%10 = ashr i32 %0, %9
%11 = and i32 %10, 255
%12 = tail call i8* @render_byte(i32 %11, i8* %6)
%13 = add i32 %7, -1
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %5, %2
%16 = phi i8* [ %1, %2 ], [ %12, %5 ]
ret i8* %16
}