#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*/ sys_write(int, char *, int);
void write_number(unsigned int x) {
  char buffer[10];
  int i, n = 0;
  while (x || n == 0) {
    buffer[n] = (x % 10) + '0';
    x /= 10;
    n++;
  }
  for (i = 0; i < (n / 2); i++) {
    char t = buffer[i];
    buffer[i] = buffer[n - i - 1];
    buffer[n - i - 1] = t;
  }
  buffer[n] = 0;
  sys_write(1, buffer, n);
}


x86 assembly (clang, -O0):
<write_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x1a(%rbp)
jne    113b <write_number+0x2b>
cmpl   $0x0,-0x18(%rbp)
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    114b <write_number+0x3b>
jmp    1181 <write_number+0x71>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    %dl,%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0xe(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1122 <write_number+0x12>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11e8 <write_number+0xd8>
movslq -0x14(%rbp),%rax
mov    -0xe(%rbp,%rax,1),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0xe(%rbp,%rax,1),%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0xe(%rbp,%rax,1)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0xe(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <write_number+0x78>
movslq -0x18(%rbp),%rax
movb   $0x0,-0xe(%rbp,%rax,1)
lea    -0xe(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <sys_write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_number>:
sub    $0x18,%rsp
movabs $0xffffffff00000000,%r10
ff ff ff
xor    %edx,%edx
mov    $0xcccccccd,%r8d
movabs $0x100000000,%r9
add    %r9,%r10
mov    %edi,%ecx
imul   %r8,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %edi,%eax
sub    %esi,%eax
or     $0x30,%al
mov    %al,0xe(%rsp,%rdx,1)
add    $0x1,%rdx
cmp    $0x9,%edi
mov    %ecx,%edi
ja     1130 <write_number+0x20>
cmp    $0x1,%edx
je     11ff <write_number+0xef>
mov    %edx,%r8d
shr    %r8d
cmp    $0x2,%r8d
mov    $0x1,%r9d
cmovb  %r9d,%r8d
cmp    $0x4,%edx
jae    1184 <write_number+0x74>
xor    %edi,%edi
test   $0x1,%r8b
jne    11e6 <write_number+0xd6>
jmp    11ff <write_number+0xef>
lea    -0x1(%rdx),%rsi
lea    0xf(%rsp),%rcx
movslq %esi,%rsi
mov    %edx,%edi
shr    %edi
cmp    $0x2,%edi
cmovae %edi,%r9d
add    %rsp,%rsi
add    $0xe,%rsi
and    $0xfffffffe,%r9d
neg    %r9
xor    %edi,%edi
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rcx),%r11d
movzbl (%rsi,%rdi,1),%eax
mov    %al,-0x1(%rcx)
mov    %r11b,(%rsi,%rdi,1)
movzbl (%rcx),%r11d
movzbl -0x1(%rsi,%rdi,1),%eax
mov    %al,(%rcx)
mov    %r11b,-0x1(%rsi,%rdi,1)
add    $0x2,%rcx
add    $0xfffffffffffffffe,%rdi
cmp    %rdi,%r9
jne    11b0 <write_number+0xa0>
neg    %rdi
test   $0x1,%r8b
je     11ff <write_number+0xef>
sar    $0x20,%r10
mov    0xe(%rsp,%rdi,1),%al
sub    %rdi,%r10
mov    0xe(%rsp,%r10,1),%cl
mov    %cl,0xe(%rsp,%rdi,1)
mov    %al,0xe(%rsp,%r10,1)
mov    %edx,%eax
movb   $0x0,0xe(%rsp,%rax,1)
lea    0xe(%rsp),%rsi
mov    $0x1,%edi
call   1030 <sys_write@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define void @write_number(i32 %0) {
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %5
br label %7
7: ; preds = %15, %1
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 0
br label %13
13: ; preds = %10, %7
%14 = phi i1 [ true, %7 ], [ %12, %10 ]
br i1 %14, label %15, label %27
15: ; preds = %13
%16 = load i32, i32* %2
%17 = urem i32 %16, 10
%18 = add i32 %17, 48
%19 = trunc i32 %18 to i8
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %21
store i8 %19, i8* %22
%23 = load i32, i32* %2
%24 = udiv i32 %23, 10
store i32 %24, i32* %2
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %7
27: ; preds = %13
store i32 0, i32* %4
br label %28
28: ; preds = %55, %27
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = sdiv i32 %30, 2
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %58
33: ; preds = %28
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %35
%37 = load i8, i8* %36
store i8 %37, i8* %6
%38 = load i32, i32* %5
%39 = load i32, i32* %4
%40 = sub nsw i32 %38, %39
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %46
store i8 %44, i8* %47
%48 = load i8, i8* %6
%49 = load i32, i32* %5
%50 = load i32, i32* %4
%51 = sub nsw i32 %49, %50
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %53
store i8 %48, i8* %54
br label %55
55: ; preds = %33
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
br label %28
58: ; preds = %28
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %60
store i8 0, i8* %61
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%63 = load i32, i32* %5
%64 = call i32 @sys_write(i32 1, i8* %62, i32 %63)
ret void
}

LLVM IR (-O2):
define void @write_number(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
br label %18
4: ; preds = %18
%5 = trunc i64 %19 to i32
%6 = trunc i64 %26 to i32
%7 = icmp eq i32 %5, 0
br i1 %7, label %54, label %8
8: ; preds = %4
%9 = lshr i32 %6, 1
%10 = shl i64 %19, 32
%11 = ashr exact i64 %10, 32
%12 = call i32 @llvm.umax.i32(i32 %9, i32 1)
%13 = zext i32 %12 to i64
%14 = and i64 %13, 1
%15 = icmp ult i32 %6, 4
br i1 %15, label %45, label %16
16: ; preds = %8
%17 = and i64 %13, 2147483646
br label %28
18: ; preds = %1, %18
%19 = phi i64 [ 0, %1 ], [ %26, %18 ]
%20 = phi i32 [ %0, %1 ], [ %25, %18 ]
%21 = urem i32 %20, 10
%22 = trunc i32 %21 to i8
%23 = or i8 %22, 48
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %19
store i8 %23, i8* %24
%25 = udiv i32 %20, 10
%26 = add nuw i64 %19, 1
%27 = icmp ugt i32 %20, 9
br i1 %27, label %18, label %4
28: ; preds = %28, %16
%29 = phi i64 [ 0, %16 ], [ %42, %28 ]
%30 = phi i64 [ 0, %16 ], [ %43, %28 ]
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %29
%32 = load i8, i8* %31
%33 = sub nsw i64 %11, %29
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %33
%35 = load i8, i8* %34
store i8 %35, i8* %31
store i8 %32, i8* %34
%36 = or i64 %29, 1
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sub nsw i64 %11, %36
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %39
%41 = load i8, i8* %40
store i8 %41, i8* %37
store i8 %38, i8* %40
%42 = add nuw nsw i64 %29, 2
%43 = add i64 %30, 2
%44 = icmp eq i64 %43, %17
br i1 %44, label %45, label %28
45: ; preds = %28, %8
%46 = phi i64 [ 0, %8 ], [ %42, %28 ]
%47 = icmp eq i64 %14, 0
br i1 %47, label %54, label %48
48: ; preds = %45
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %46
%50 = load i8, i8* %49
%51 = sub nsw i64 %11, %46
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %51
%53 = load i8, i8* %52
store i8 %53, i8* %49
store i8 %50, i8* %52
br label %54
54: ; preds = %48, %45, %4
%55 = and i64 %26, 4294967295
%56 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %55
store i8 0, i8* %56
%57 = call i32 @sys_write(i32 1, i8* %3, i32 %6)
ret void
}