#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 abs(int);
int /*<<< orphan*/ write(int, char *, int);
void fwriteInt(int f, int v) {
  static const int N = 20;
  char string[N];
  char *s = string + N;
  int isNegative = v < 0;
  v = abs(v);
  if (v == 0) {
    *--s = '0';
  }
  while (v > 0) {
    int d = (v % 10);
    *--s = ('0' + d);
    v = v / 10;
  }
  if (isNegative) {
    *--s = '-';
  }
  int numChars = string + N - s;
  write(f, s, numChars);
}


x86 assembly (clang, -O0):
<fwriteInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
lea    -0x40(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1178 <fwriteInt+0x58>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x30,-0x1(%rax)
jmp    117d <fwriteInt+0x5d>
cmpl   $0x0,-0x8(%rbp)
jle    11c2 <fwriteInt+0xa2>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    117d <fwriteInt+0x5d>
cmpl   $0x0,-0x1c(%rbp)
je     11df <fwriteInt+0xbf>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,-0x1(%rax)
lea    -0x40(%rbp),%rax
add    $0x14,%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwriteInt>:
sub    $0x18,%rsp
mov    %esi,%r8d
lea    0x14(%rsp),%rdx
test   %esi,%esi
je     117c <fwriteInt+0x6c>
mov    %r8d,%r10d
neg    %r10d
cmovs  %r8d,%r10d
mov    $0xcccccccd,%r9d
mov    %rdx,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r10d,%eax
imul   %r9,%rax
shr    $0x23,%rax
lea    (%rax,%rax,1),%ecx
lea    (%rcx,%rcx,4),%r11d
mov    %r10d,%ecx
sub    %r11d,%ecx
or     $0x30,%cl
mov    %cl,-0x1(%rsi)
add    $0xffffffffffffffff,%rsi
cmp    $0x9,%r10d
mov    %eax,%r10d
ja     1140 <fwriteInt+0x30>
test   %r8d,%r8d
js     118b <fwriteInt+0x7b>
sub    %esi,%edx
call   1030 <write@plt>
add    $0x18,%rsp
ret
lea    0x13(%rsp),%rsi
movb   $0x30,0x13(%rsp)
test   %r8d,%r8d
jns    1170 <fwriteInt+0x60>
movb   $0x2d,-0x1(%rsi)
add    $0xffffffffffffffff,%rsi
jmp    1170 <fwriteInt+0x60>

LLVM IR (-O0):
@fwriteInt.N = internal constant i32 20
define void @fwriteInt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 20
%12 = getelementptr inbounds i8, i8* %11, i64 20
store i8* %12, i8** %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
%15 = zext i1 %14 to i32
store i32 %15, i32* %7
%16 = load i32, i32* %4
%17 = call i32 @abs(i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i32 -1
store i8* %22, i8** %6
store i8 48, i8* %22
br label %23
23: ; preds = %20, %2
br label %24
24: ; preds = %27, %23
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i32, i32* %4
%29 = srem i32 %28, 10
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = add nsw i32 48, %30
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i32 -1
store i8* %34, i8** %6
store i8 %32, i8* %34
%35 = load i32, i32* %4
%36 = sdiv i32 %35, 10
store i32 %36, i32* %4
br label %24
37: ; preds = %24
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i32 -1
store i8* %42, i8** %6
store i8 45, i8* %42
br label %43
43: ; preds = %40, %37
%44 = getelementptr inbounds i8, i8* %11, i64 20
%45 = load i8*, i8** %6
%46 = ptrtoint i8* %44 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
%49 = trunc i64 %48 to i32
store i32 %49, i32* %9
%50 = load i32, i32* %3
%51 = load i8*, i8** %6
%52 = load i32, i32* %9
%53 = call i32 @write(i32 %50, i8* %51, i32 %52)
%54 = load i8*, i8** %5
ret void
}

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