#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ write_str(char *);
void write_uint32(uint32_t v) {
  char s[20], *s1, *s2, c;
  s1 = s;
  if (v == 0)
    *s1++ = '0';
  s2 = s1;
  while (v > 0) {
    *s2++ = (v % 10) + '0';
    v /= 10;
  }
  *s2-- = 0;
  while (s2 > s1) {
    c = *s1;
    *s1 = *s2;
    *s2 = c;
    s1++;
    s2--;
  }
  write_str(s);
}


x86 assembly (clang, -O0):
<write_uint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    113f <write_uint32+0x2f>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x30,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1185 <write_uint32+0x75>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1147 <write_uint32+0x37>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    11e0 <write_uint32+0xd0>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x31(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x31(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1197 <write_uint32+0x87>
lea    -0x20(%rbp),%rdi
call   1030 <write_str@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_uint32>:
sub    $0x18,%rsp
test   %edi,%edi
je     1158 <write_uint32+0x48>
mov    %rsp,%rax
jle    1161 <write_uint32+0x51>
mov    $0xcccccccd,%r8d
mov    %rax,%rcx
cs nopw 0x0(%rax,%rax,1)
mov    %edi,%esi
imul   %r8,%rsi
shr    $0x23,%rsi
lea    (%rsi,%rsi,1),%edx
lea    (%rdx,%rdx,4),%r9d
mov    %edi,%edx
sub    %r9d,%edx
or     $0x30,%dl
mov    %dl,(%rcx)
add    $0x1,%rcx
cmp    $0x9,%edi
mov    %esi,%edi
ja     1130 <write_uint32+0x20>
jmp    1164 <write_uint32+0x54>
lea    0x1(%rsp),%rax
movb   $0x30,(%rsp)
mov    %rax,%rcx
movb   $0x0,(%rcx)
add    $0xffffffffffffffff,%rcx
cmp    %rax,%rcx
jbe    119d <write_uint32+0x8d>
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%rax),%esi
movzbl (%rcx),%edx
mov    %dl,-0x1(%rax)
mov    %sil,(%rcx)
add    $0xffffffffffffffff,%rcx
lea    0x1(%rax),%rdx
cmp    %rax,%rcx
mov    %rdx,%rax
ja     1180 <write_uint32+0x70>
mov    %rsp,%rdi
call   1030 <write_str@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define void @write_uint32(i32 %0) {
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
store i32 %0, i32* %2
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
store i8* %7, i8** %4
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %4
store i8 48, i8* %11
br label %13
13: ; preds = %10, %1
%14 = load i8*, i8** %4
store i8* %14, i8** %5
br label %15
15: ; preds = %18, %13
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i32, i32* %2
%20 = srem i32 %19, 10
%21 = add nsw i32 %20, 48
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
store i8 %22, i8* %23
%25 = load i32, i32* %2
%26 = sdiv i32 %25, 10
store i32 %26, i32* %2
br label %15
27: ; preds = %15
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %5
store i8 0, i8* %28
br label %30
30: ; preds = %34, %27
%31 = load i8*, i8** %5
%32 = load i8*, i8** %4
%33 = icmp ugt i8* %31, %32
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
store i8 %36, i8* %6
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = load i8*, i8** %4
store i8 %38, i8* %39
%40 = load i8, i8* %6
%41 = load i8*, i8** %5
store i8 %40, i8* %41
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 -1
store i8* %45, i8** %5
br label %30
46: ; preds = %30
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%48 = call i32 @write_str(i8* %47)
ret void
}

LLVM IR (-O2):
define void @write_uint32(i32 %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 1
store i8 48, i8* %3
br label %18
7: ; preds = %1
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %18
9: ; preds = %7, %9
%10 = phi i32 [ %16, %9 ], [ %0, %7 ]
%11 = phi i8* [ %15, %9 ], [ %3, %7 ]
%12 = urem i32 %10, 10
%13 = trunc i32 %12 to i8
%14 = or i8 %13, 48
%15 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %14, i8* %11
%16 = udiv i32 %10, 10
%17 = icmp ult i32 %10, 10
br i1 %17, label %18, label %9
18: ; preds = %9, %5, %7
%19 = phi i8* [ %3, %7 ], [ %6, %5 ], [ %3, %9 ]
%20 = phi i8* [ %3, %7 ], [ %6, %5 ], [ %15, %9 ]
store i8 0, i8* %20
%21 = getelementptr inbounds i8, i8* %20, i64 -1
%22 = icmp ugt i8* %21, %19
br i1 %22, label %23, label %31
23: ; preds = %18, %23
%24 = phi i8* [ %29, %23 ], [ %21, %18 ]
%25 = phi i8* [ %28, %23 ], [ %19, %18 ]
%26 = load i8, i8* %25
%27 = load i8, i8* %24
store i8 %27, i8* %25
store i8 %26, i8* %24
%28 = getelementptr inbounds i8, i8* %25, i64 1
%29 = getelementptr inbounds i8, i8* %24, i64 -1
%30 = icmp ugt i8* %29, %28
br i1 %30, label %23, label %31
31: ; preds = %23, %18
%32 = call i32 @write_str(i8* %3)
ret void
}