#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void write_int(int d, FILE *file) {
  static char write_int_buffer[16];
  unsigned tmp;
  char *res;
  int sign;
  assert(sizeof d <= 4);
  res = write_int_buffer + sizeof write_int_buffer;
  *--res = 0;
  sign = (d < 0);
  if (sign)
    tmp = (unsigned)-d;
  else
    tmp = d;
  do {
    assert(res > write_int_buffer);
    *--res = '0' + (tmp % 10);
    tmp /= 10;
  } while (tmp);
  if (sign) {
    assert(res > write_int_buffer);
    *--res = '-';
  }
  fputs(res, file);
}


x86 assembly (clang, -O0):
<write_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1040 <assert@plt>
lea    0x2f00(%rip),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,-0x1(%rax)
cmpl   $0x0,-0x4(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1181 <write_int+0x61>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1187 <write_int+0x67>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    118c <write_int+0x6c>
lea    0x2ead(%rip),%rax
cmp    %rax,-0x20(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    118c <write_int+0x6c>
cmpl   $0x0,-0x24(%rbp)
je     1215 <write_int+0xf5>
lea    0x2e4f(%rip),%rax
cmp    %rax,-0x20(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2d,-0x1(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fputs@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x1,%edi
call   1040 <assert@plt>
mov    %r15d,%ebp
neg    %ebp
cmovs  %r15d,%ebp
movb   $0x0,0x2f04(%rip)
lea    0x2efc(%rip),%rbx
lea    0x2ee7(%rip),%r12
mov    $0xcccccccd,%r13d
nop
lea    0x1(%rbx),%rax
xor    %edi,%edi
cmp    %r12,%rax
seta   %dil
call   1040 <assert@plt>
mov    %ebp,%eax
imul   %r13,%rax
shr    $0x23,%rax
lea    (%rax,%rax,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %ebp,%edx
sub    %ecx,%edx
or     $0x30,%dl
mov    %dl,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    $0x9,%ebp
mov    %eax,%ebp
ja     1160 <write_int+0x40>
lea    0x1(%rbx),%rdi
test   %r15d,%r15d
jns    11b4 <write_int+0x94>
xor    %eax,%eax
cmp    %r12,%rdi
seta   %al
mov    %eax,%edi
call   1040 <assert@plt>
movb   $0x2d,(%rbx)
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputs@plt>

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

LLVM IR (-O2):
@write_int.write_int_buffer = internal global [16 x i8] zeroinitializer
define void @write_int(i32 %0, i32* nocapture %1) {
%3 = tail call i32 @assert(i32 1)
store i8 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @write_int.write_int_buffer, i64 0, i64 15)
%4 = icmp slt i32 %0, 0
%5 = sub nsw i32 0, %0
%6 = select i1 %4, i32 %5, i32 %0
br label %7
7: ; preds = %7, %2
%8 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @write_int.write_int_buffer, i64 0, i64 15), %2 ], [ %16, %7 ]
%9 = phi i32 [ %6, %2 ], [ %17, %7 ]
%10 = icmp ugt i8* %8, getelementptr inbounds ([16 x i8], [16 x i8]* @write_int.write_int_buffer, i64 0, i64 0)
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = urem i32 %9, 10
%14 = trunc i32 %13 to i8
%15 = or i8 %14, 48
%16 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %15, i8* %16
%17 = udiv i32 %9, 10
%18 = icmp ult i32 %9, 10
br i1 %18, label %19, label %7
19: ; preds = %7
br i1 %4, label %20, label %25
20: ; preds = %19
%21 = icmp ugt i8* %16, getelementptr inbounds ([16 x i8], [16 x i8]* @write_int.write_int_buffer, i64 0, i64 0)
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = getelementptr inbounds i8, i8* %8, i64 -2
store i8 45, i8* %24
br label %25
25: ; preds = %20, %19
%26 = phi i8* [ %24, %20 ], [ %16, %19 ]
%27 = tail call i32 @fputs(i8* %26, i32* %1)
ret void
}