#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*/ fmt_int(char *, char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, int /*<<< orphan*/);
char *fmt_exp(int val, char *fmt) {
  static char buf[256];
  register char *bufptr = buf;
  char valbuf[64];
  int negative = 0;
  *bufptr++ = *fmt++;
  if (*fmt == '+')
    *bufptr++ = (val < 0) ? '-' : '+';
  else if (val < 0)
    *bufptr++ = '-';
  fmt++;
  *bufptr = '\0';
  if (val < 0) {
    val = -val;
    negative = 0;
  }
  (void)sprintf(valbuf, "%d", val);
  (void)strcat(buf, fmt_int(valbuf, fmt, 0, negative));
  return (buf);
}


x86 assembly (clang, -O0):
<fmt_exp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0x2f0a(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11ae <fmt_exp+0x7e>
mov    -0x4(%rbp),%edx
mov    $0x2b,%eax
mov    $0x2d,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11cf <fmt_exp+0x9f>
cmpl   $0x0,-0x4(%rbp)
jge    11ca <fmt_exp+0x9a>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
jmp    11cf <fmt_exp+0x9f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x4(%rbp)
jge    11fb <fmt_exp+0xcb>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x64(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xdf7(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x64(%rbp),%ecx
xor    %edx,%edx
call   1030 <fmt_int@plt>
mov    %eax,%esi
lea    0x2e27(%rip),%rdi
call   1040 <strcat@plt>
lea    0x2e1b(%rip),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt_exp>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    (%rsi),%al
mov    %al,0x2f0e(%rip)
cmpb   $0x2b,0x1(%rsi)
jne    1153 <fmt_exp+0x23>
mov    %edi,%eax
shr    $0x1f,%eax
add    %al,%al
add    $0x2b,%al
jmp    1162 <fmt_exp+0x32>
test   %edi,%edi
js     1160 <fmt_exp+0x30>
lea    0x2ef3(%rip),%rax
jmp    116f <fmt_exp+0x3f>
mov    $0x2d,%al
mov    %al,0x2ee9(%rip)
lea    0x2ee3(%rip),%rax
movb   $0x0,(%rax)
mov    %edi,%edx
neg    %edx
cmovs  %edi,%edx
add    $0x2,%rbx
lea    0xe7c(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <fmt_int@plt>
lea    0x2eab(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <strcat@plt>
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@fmt_exp.buf = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @fmt_exp(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [64 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @fmt_exp.buf, i64 0, i64 0), i8** %5
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %4
%10 = load i8, i8* %8
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %5
store i8 %10, i8* %11
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 43
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 45, i32 43
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
store i8 %22, i8* %23
br label %32
25: ; preds = %2
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
store i8 45, i8* %29
br label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31, %17
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %4
%35 = load i8*, i8** %5
store i8 0, i8* %35
%36 = load i32, i32* %3
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i32, i32* %3
%40 = sub nsw i32 0, %39
store i32 %40, i32* %3
store i32 0, i32* %7
br label %41
41: ; preds = %38, %32
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%43 = load i32, i32* %3
%44 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%46 = load i8*, i8** %4
%47 = load i32, i32* %7
%48 = call i32 @fmt_int(i8* %45, i8* %46, i32 0, i32 %47)
%49 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @fmt_exp.buf, i64 0, i64 0), i32 %48)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @fmt_exp.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@fmt_exp.buf = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @fmt_exp(i32 %0, i8* %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8, i8* %1, i64 1
%6 = load i8, i8* %1
store i8 %6, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @fmt_exp.buf, i64 0, i64 0)
%7 = load i8, i8* %5
%8 = icmp eq i8 %7, 43
%9 = icmp slt i32 %0, 0
br i1 %8, label %10, label %12
10: ; preds = %2
%11 = select i1 %9, i8 45, i8 43
br label %13
12: ; preds = %2
br i1 %9, label %13, label %15
13: ; preds = %12, %10
%14 = phi i8 [ %11, %10 ], [ 45, %12 ]
store i8 %14, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @fmt_exp.buf, i64 0, i64 1)
br label %15
15: ; preds = %13, %12
%16 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @fmt_exp.buf, i64 0, i64 1), %12 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @fmt_exp.buf, i64 0, i64 2), %13 ]
store i8 0, i8* %16
%17 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%18 = getelementptr inbounds i8, i8* %1, i64 2
%19 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
%20 = call i32 @fmt_int(i8* %4, i8* %18, i32 0, i32 0)
%21 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @fmt_exp.buf, i64 0, i64 0), i32 %20)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @fmt_exp.buf, i64 0, i64 0)
}