#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 */
unsigned int write_uint(char *, unsigned int, long, unsigned int);
unsigned int write_int(char *dst, unsigned int len, long val,
                       unsigned int base) {
  if (len == 0)
    return 0;
  if (val < 0) {
    *dst = '-';
    return 1 + write_uint(dst + 1, len - 1, -val, base);
  }
  return write_uint(dst, len, val, base);
}


x86 assembly (clang, -O0):
<write_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    113c <write_int+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    118d <write_int+0x7d>
cmpq   $0x0,-0x20(%rbp)
jge    1177 <write_int+0x67>
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
sub    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1030 <write_uint@plt>
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    118d <write_int+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1030 <write_uint@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_int>:
test   %esi,%esi
je     111e <write_int+0xe>
test   %rdx,%rdx
js     1121 <write_int+0x11>
jmp    1030 <write_uint@plt>
xor    %eax,%eax
ret
push   %rax
movb   $0x2d,(%rdi)
add    $0x1,%rdi
add    $0xffffffff,%esi
neg    %rdx
call   1030 <write_uint@plt>
add    $0x1,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
define i32 @write_int(i8* %0, i32 %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i64 %2, i64* %8
store i32 %3, i32* %9
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %4
store i32 0, i32* %5
br label %33
13: ; preds = %4
%14 = load i64, i64* %8
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i8*, i8** %6
store i8 45, i8* %17
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i32, i32* %7
%21 = sub i32 %20, 1
%22 = load i64, i64* %8
%23 = sub nsw i64 0, %22
%24 = load i32, i32* %9
%25 = call i32 @write_uint(i8* %19, i32 %21, i64 %23, i32 %24)
%26 = add i32 1, %25
store i32 %26, i32* %5
br label %33
27: ; preds = %13
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = load i64, i64* %8
%31 = load i32, i32* %9
%32 = call i32 @write_uint(i8* %28, i32 %29, i64 %30, i32 %31)
store i32 %32, i32* %5
br label %33
33: ; preds = %27, %16, %12
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
define i32 @write_int(i8* %0, i32 %1, i64 %2, i32 %3) {
%5 = icmp eq i32 %1, 0
br i1 %5, label %16, label %6
6: ; preds = %4
%7 = icmp slt i64 %2, 0
br i1 %7, label %8, label %14
8: ; preds = %6
store i8 45, i8* %0
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = add i32 %1, -1
%11 = sub nsw i64 0, %2
%12 = tail call i32 @write_uint(i8* %9, i32 %10, i64 %11, i32 %3)
%13 = add i32 %12, 1
br label %16
14: ; preds = %6
%15 = tail call i32 @write_uint(i8* %0, i32 %1, i64 %2, i32 %3)
br label %16
16: ; preds = %4, %14, %8
%17 = phi i32 [ %13, %8 ], [ %15, %14 ], [ 0, %4 ]
ret i32 %17
}