#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*/ put_string(char *);
void put_int(int i) {
  char buf[11];
  buf[10] = 0;
  char *bufp = buf + 10;
  do {
    *--bufp = '0' + (i % 10);
    i /= 10;
  } while (i != 0);
  put_string(bufp);
}


x86 assembly (clang, -O0):
<put_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
lea    -0xf(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    112b <put_int+0x1b>
mov    -0x18(%rbp),%rdi
call   1030 <put_string@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_int>:
sub    $0x18,%rsp
mov    %edi,%eax
lea    0x17(%rsp),%rdi
movb   $0x0,0x17(%rsp)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
lea    (%rax,%rax,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0x30,%sil
mov    %sil,-0x1(%rdi)
add    $0xffffffffffffffff,%rdi
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1120 <put_int+0x10>
call   1030 <put_string@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define void @put_int(i32 %0) {
%2 = alloca i32
%3 = alloca [11 x i8]
%4 = alloca i8*
store i32 %0, i32* %2
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 10
store i8 0, i8* %5
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds i8, i8* %6, i64 10
store i8* %7, i8** %4
br label %8
8: ; preds = %17, %1
%9 = load i32, i32* %2
%10 = srem i32 %9, 10
%11 = add nsw i32 48, %10
%12 = trunc i32 %11 to i8
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 -1
store i8* %14, i8** %4
store i8 %12, i8* %14
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 10
store i32 %16, i32* %2
br label %17
17: ; preds = %8
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
br i1 %19, label %8, label %20
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = call i32 @put_string(i8* %21)
ret void
}

LLVM IR (-O2):
define void @put_int(i32 %0) {
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 10
store i8 0, i8* %4
br label %5
5: ; preds = %5, %1
%6 = phi i32 [ %0, %1 ], [ %12, %5 ]
%7 = phi i8* [ %4, %1 ], [ %11, %5 ]
%8 = srem i32 %6, 10
%9 = trunc i32 %8 to i8
%10 = add nsw i8 %9, 48
%11 = getelementptr inbounds i8, i8* %7, i64 -1
store i8 %10, i8* %11
%12 = sdiv i32 %6, 10
%13 = add i32 %6, 9
%14 = icmp ult i32 %13, 19
br i1 %14, label %15, label %5
15: ; preds = %5
%16 = call i32 @put_string(i8* %11)
ret void
}