#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*/ wad_format_unsigned(unsigned long, int);
int /*<<< orphan*/ wad_strcat(char *, int /*<<< orphan*/);
char *wad_format_signed(signed long s, int width) {
  static char result[128];
  unsigned long u;
  char *c = result;
  if (s < 0) {
    *(c++) = '-';
    width--;
    u = (unsigned long)(-s);
    if (u == 0) {
      u = (unsigned long)s;
    }
  } else {
    u = (unsigned long)s;
  }
  *c = 0;
  wad_strcat(result, wad_format_unsigned(u, width));
  return result;
}


x86 assembly (clang, -O0):
<wad_format_signed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0x2f0a(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1182 <wad_format_signed+0x62>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2d,(%rax)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
sub    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117d <wad_format_signed+0x5d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    118a <wad_format_signed+0x6a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <wad_format_unsigned@plt>
mov    %eax,%esi
lea    0x2e9a(%rip),%rdi
call   1040 <wad_strcat@plt>
lea    0x2e8e(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wad_format_signed>:
push   %rbx
test   %rdi,%rdi
js     112f <wad_format_signed+0xf>
lea    0x2f13(%rip),%rax
jmp    1143 <wad_format_signed+0x23>
movb   $0x2d,0x2f0a(%rip)
add    $0xffffffff,%esi
neg    %rdi
lea    0x2efe(%rip),%rax
movb   $0x0,(%rax)
call   1030 <wad_format_unsigned@plt>
lea    0x2eee(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <wad_strcat@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@wad_format_signed.result = internal global [128 x i8] zeroinitializer
define i8* @wad_format_signed(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
store i64 %0, i64* %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @wad_format_signed.result, i64 0, i64 0), i8** %6
%7 = load i64, i64* %3
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %2
%10 = load i8*, i8** %6
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %6
store i8 45, i8* %10
%12 = load i32, i32* %4
%13 = add nsw i32 %12, -1
store i32 %13, i32* %4
%14 = load i64, i64* %3
%15 = sub nsw i64 0, %14
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = load i64, i64* %3
store i64 %19, i64* %5
br label %20
20: ; preds = %18, %9
br label %23
21: ; preds = %2
%22 = load i64, i64* %3
store i64 %22, i64* %5
br label %23
23: ; preds = %21, %20
%24 = load i8*, i8** %6
store i8 0, i8* %24
%25 = load i64, i64* %5
%26 = load i32, i32* %4
%27 = call i32 @wad_format_unsigned(i64 %25, i32 %26)
%28 = call i32 @wad_strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @wad_format_signed.result, i64 0, i64 0), i32 %27)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @wad_format_signed.result, i64 0, i64 0)
}

LLVM IR (-O2):
@wad_format_signed.result = internal global [128 x i8] zeroinitializer
define i8* @wad_format_signed(i64 %0, i32 %1) {
%3 = icmp slt i64 %0, 0
br i1 %3, label %4, label %7
4: ; preds = %2
store i8 45, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @wad_format_signed.result, i64 0, i64 0)
%5 = add nsw i32 %1, -1
%6 = sub nsw i64 0, %0
br label %7
7: ; preds = %2, %4
%8 = phi i32 [ %5, %4 ], [ %1, %2 ]
%9 = phi i64 [ %6, %4 ], [ %0, %2 ]
%10 = phi i8* [ getelementptr inbounds ([128 x i8], [128 x i8]* @wad_format_signed.result, i64 0, i64 1), %4 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @wad_format_signed.result, i64 0, i64 0), %2 ]
store i8 0, i8* %10
%11 = tail call i32 @wad_format_unsigned(i64 %9, i32 %8)
%12 = tail call i32 @wad_strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @wad_format_signed.result, i64 0, i64 0), i32 %11)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @wad_format_signed.result, i64 0, i64 0)
}