#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*/ sprintf(char *, char *, int);
size_t strlen(char *);
char *num(int n1, int n2, char type) {
  static char numbuf[10];
  sprintf(numbuf, n1 < 0 ? "%d" : "+%d", n1);
  if (type == ')')
    sprintf(&numbuf[strlen(numbuf)], n2 < 0 ? ",%d" : ",+%d", n2);
  return numbuf;
}


x86 assembly (clang, -O0):
<num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x4(%rbp),%ecx
lea    0xec8(%rip),%rsi
lea    0xec2(%rip),%rax
cmp    $0x0,%ecx
cmovl  %rax,%rsi
mov    -0x4(%rbp),%edx
lea    0x2edc(%rip),%rdi
call   1040 <sprintf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x29,%eax
jne    119d <num+0x7d>
lea    0x2ec3(%rip),%rdi
call   1030 <strlen@plt>
lea    0x2eb7(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%ecx
lea    0xe7d(%rip),%rsi
lea    0xe72(%rip),%rax
cmp    $0x0,%ecx
cmovl  %rax,%rsi
mov    -0x8(%rbp),%edx
call   1040 <sprintf@plt>
lea    0x2e8d(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%edx
test   %edi,%edi
lea    0xed2(%rip),%rax
lea    0xeca(%rip),%rsi
cmovs  %rax,%rsi
lea    0x2eeb(%rip),%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
cmp    $0x29,%bpl
jne    117f <num+0x5f>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %rax,%rbx
test   %r14d,%r14d
lea    0xe97(%rip),%rax
lea    0xe94(%rip),%rsi
cmovs  %rax,%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <sprintf@plt>
lea    0x2eab(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@num.numbuf = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"+%d\00"
@.str.2 = [4 x i8] c",%d\00"
@.str.3 = [5 x i8] c",+%d\00"
define i8* @num(i32 %0, i32 %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8 %2, i8* %6
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
%9 = zext i1 %8 to i64
%10 = select i1 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%11 = load i32, i32* %4
%12 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @num.numbuf, i64 0, i64 0), i8* %10, i32 %11)
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 41
br i1 %15, label %16, label %25
16: ; preds = %3
%17 = call i64 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @num.numbuf, i64 0, i64 0))
%18 = getelementptr inbounds [10 x i8], [10 x i8]* @num.numbuf, i64 0, i64 %17
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%23 = load i32, i32* %5
%24 = call i32 @sprintf(i8* %18, i8* %22, i32 %23)
br label %25
25: ; preds = %16, %3
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @num.numbuf, i64 0, i64 0)
}

LLVM IR (-O2):
@num.numbuf = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"+%d\00"
@.str.2 = [4 x i8] c",%d\00"
@.str.3 = [5 x i8] c",+%d\00"
define i8* @num(i32 %0, i32 %1, i8 signext %2) {
%4 = icmp slt i32 %0, 0
%5 = select i1 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%6 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @num.numbuf, i64 0, i64 0), i8* dereferenceable(1) %5, i32 %0)
%7 = icmp eq i8 %2, 41
br i1 %7, label %8, label %14
8: ; preds = %3
%9 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @num.numbuf, i64 0, i64 0))
%10 = getelementptr inbounds [10 x i8], [10 x i8]* @num.numbuf, i64 0, i64 %9
%11 = icmp slt i32 %1, 0
%12 = select i1 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%13 = tail call i32 @sprintf(i8* %10, i8* dereferenceable(1) %12, i32 %1)
br label %14
14: ; preds = %8, %3
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @num.numbuf, i64 0, i64 0)
}