#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*/ write_char(char);
int write_int(int d) {
  char buf[100];
  int p = 0, ret;
  unsigned int u;
  if (d < 0) {
    write_char('-');
    d = -d;
  }
  u = d;
  do {
    buf[p++] = u % 10;
    u /= 10;
  } while (u > 0);
  ret = p;
  while (p > 0)
    write_char('0' + buf[--p]);
  return ret;
}


x86 assembly (clang, -O0):
<write_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x74(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1141 <write_int+0x31>
mov    $0x2d,%edi
call   1030 <write_char@plt>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %dl,%cl
mov    -0x74(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x74(%rbp)
cltq
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x7c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
ja     1147 <write_int+0x37>
mov    -0x74(%rbp),%eax
mov    %eax,-0x78(%rbp)
cmpl   $0x0,-0x74(%rbp)
jle    11af <write_int+0x9f>
mov    -0x74(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
cltq
movsbl -0x70(%rbp,%rax,1),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <write_char@plt>
jmp    1185 <write_int+0x75>
mov    -0x78(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %edi,%ebp
test   %edi,%edi
jns    112a <write_int+0x1a>
mov    $0x2d,%edi
call   1030 <write_char@plt>
neg    %ebp
xor    %r14d,%r14d
mov    $0xcccccccd,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ebp,%esi
sub    %edx,%esi
mov    %sil,(%rsp,%r14,1)
add    $0x1,%r14
cmp    $0x9,%ebp
mov    %ecx,%ebp
ja     1140 <write_int+0x30>
mov    %r14d,%ebp
add    $0xffffffffffffffff,%rbp
lea    0x1(%r14),%ebx
xchg   %ax,%ax
mov    %ebp,%eax
movzbl (%rsp,%rax,1),%eax
add    $0x30,%al
movsbl %al,%edi
call   1030 <write_char@plt>
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%ebx
jg     1170 <write_int+0x60>
mov    %r14d,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @write_int(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @write_char(i8 signext 45)
%7 = sub nsw i32 0, %0
br label %8
8: ; preds = %5, %1
%9 = phi i32 [ %0, %1 ], [ %7, %5 ]
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %15, %10 ], [ 0, %8 ]
%12 = phi i32 [ %17, %10 ], [ %9, %8 ]
%13 = urem i32 %12, 10
%14 = trunc i32 %13 to i8
%15 = add nuw i64 %11, 1
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %11
store i8 %14, i8* %16
%17 = udiv i32 %12, 10
%18 = icmp ult i32 %12, 10
br i1 %18, label %19, label %10
19: ; preds = %10
%20 = and i64 %15, 4294967295
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ %20, %19 ], [ %23, %21 ]
%23 = add nsw i64 %22, -1
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = add i8 %26, 48
%28 = tail call i32 @write_char(i8 signext %27)
%29 = trunc i64 %22 to i32
%30 = icmp sgt i32 %29, 1
br i1 %30, label %21, label %31
31: ; preds = %21
%32 = trunc i64 %15 to i32
ret i32 %32
}