#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*/ syscall_write(int, char *, int);
int /*<<< orphan*/ write_char(int);
void write_int(int n) {
  int k, leading_zeros, div;
  if (n < 0) {
    syscall_write(1, "-", sizeof("-"));
    n *= -1;
  }
  if (n == 0) {
    write_char('0');
    return;
  }
  k = 1000000000;
  leading_zeros = 1;
  while (k > 0) {
    div = n / k;
    if (leading_zeros && div != 0) {
      leading_zeros = 0;
    }
    if (!leading_zeros) {
      write_char(div + '0');
    }
    n %= k;
    k /= 10;
  }
}


x86 assembly (clang, -O0):
<write_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1152 <write_int+0x32>
mov    $0x1,%edi
lea    0xebf(%rip),%rsi
mov    $0x2,%edx
call   1030 <syscall_write@plt>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    116b <write_int+0x4b>
mov    $0x30,%edi
call   1040 <write_char@plt>
jmp    11dc <write_int+0xbc>
movl   $0x3b9aca00,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11dc <write_int+0xbc>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a8 <write_int+0x88>
cmpl   $0x0,-0x10(%rbp)
je     11a8 <write_int+0x88>
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11bd <write_int+0x9d>
mov    -0x10(%rbp),%edi
add    $0x30,%edi
call   1040 <write_char@plt>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1179 <write_int+0x59>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_int>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r12d
test   %edi,%edi
js     1143 <write_int+0x23>
jne    115c <write_int+0x3c>
mov    $0x30,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <write_char@plt>
lea    0xeb6(%rip),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1030 <syscall_write@plt>
neg    %r12d
mov    $0x3b9aca00,%ebx
mov    $0x1,%ebp
xor    %r14d,%r14d
mov    $0xcccccccd,%r15d
jmp    1191 <write_int+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
imul   %r15,%rax
shr    $0x23,%rax
cmp    $0x9,%ebx
mov    %eax,%ebx
jbe    11b7 <write_int+0x97>
mov    %r12d,%eax
cltd
idiv   %ebx
mov    %ebp,%ecx
test   %eax,%eax
cmovne %r14d,%ebp
test   %ecx,%ecx
cmove  %ecx,%ebp
mov    %edx,%r12d
test   %ebp,%ebp
jne    1180 <write_int+0x60>
add    $0x30,%eax
mov    %eax,%edi
call   1040 <write_char@plt>
jmp    1180 <write_int+0x60>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
define void @write_int(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @syscall_write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
%5 = sub nsw i32 0, %0
br label %8
6: ; preds = %1
%7 = icmp eq i32 %0, 0
br i1 %7, label %10, label %8
8: ; preds = %3, %6
%9 = phi i32 [ %0, %6 ], [ %5, %3 ]
br label %12
10: ; preds = %6
%11 = tail call i32 @write_char(i32 48)
br label %29
12: ; preds = %8, %26
%13 = phi i32 [ %17, %26 ], [ %9, %8 ]
%14 = phi i32 [ %21, %26 ], [ 1, %8 ]
%15 = phi i32 [ %27, %26 ], [ 1000000000, %8 ]
%16 = sdiv i32 %13, %15
%17 = srem i32 %13, %15
%18 = icmp ne i32 %14, 0
%19 = icmp ne i32 %16, 0
%20 = select i1 %18, i1 %19, i1 false
%21 = select i1 %20, i32 0, i32 %14
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = add nsw i32 %16, 48
%25 = tail call i32 @write_char(i32 %24)
br label %26
26: ; preds = %23, %12
%27 = udiv i32 %15, 10
%28 = icmp ult i32 %15, 10
br i1 %28, label %29, label %12
29: ; preds = %26, %10
ret void
}