#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 */
char *printf_format_uint(int, int, char);
char *printf_format_int(int value, int width, char fill) {
  char sign = 0;
  char *result;
  if (value < 0) {
    sign = '-';
    value = ~value;
    value++;
    if (width > 1) {
      width--;
    }
  }
  result = printf_format_uint(value, width, fill);
  if (sign) {
    result--;
    *result = sign;
  }
  return result;
}


x86 assembly (clang, -O0):
<printf_format_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movb   $0x0,-0xa(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    115f <printf_format_int+0x4f>
movb   $0x2d,-0xa(%rbp)
mov    -0x4(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    115a <printf_format_int+0x4a>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    115f <printf_format_int+0x4f>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
movsbl -0x9(%rbp),%edx
call   1030 <printf_format_uint@plt>
mov    %rax,-0x18(%rbp)
cmpb   $0x0,-0xa(%rbp)
je     1191 <printf_format_int+0x81>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0xa(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_format_int>:
test   %edi,%edi
js     111c <printf_format_int+0xc>
movsbl %dl,%edx
jmp    1030 <printf_format_uint@plt>
push   %rax
neg    %edi
xor    %eax,%eax
cmp    $0x2,%esi
setge  %al
sub    %eax,%esi
movsbl %dl,%edx
call   1030 <printf_format_uint@plt>
movb   $0x2d,-0x1(%rax)
add    $0xffffffffffffffff,%rax
pop    %rcx
ret

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

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