#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*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *reserved_or_num(char *buff, int buff_len, int num, int reserve_num) {
  if (num == reserve_num)
    strncpy(buff, "<res>", buff_len);
  else
    snprintf(buff, buff_len, "%d", num);
  if (buff_len > 0)
    buff[buff_len - 1] = '\0';
  return buff;
}


x86 assembly (clang, -O0):
<reserved_or_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1159 <reserved_or_num+0x39>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xeb1(%rip),%rsi
call   1030 <strncpy@plt>
jmp    116f <reserved_or_num+0x4f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
lea    0xe9c(%rip),%rdx
call   1040 <snprintf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    118a <reserved_or_num+0x6a>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reserved_or_num>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
cmp    %ecx,%edx
jne    1144 <reserved_or_num+0x24>
lea    0xecc(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
test   %ebx,%ebx
jg     115d <reserved_or_num+0x3d>
jmp    1165 <reserved_or_num+0x45>
mov    %edx,%eax
lea    0xeb9(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
test   %ebx,%ebx
jle    1165 <reserved_or_num+0x45>
add    $0xffffffff,%ebx
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"<res>\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @reserved_or_num(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %7
%10 = load i32, i32* %8
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = call i32 @strncpy(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %21
16: ; preds = %4
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = call i32 @snprintf(i8* %17, i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %16, %12
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %24, %21
%31 = load i8*, i8** %5
ret i8* %31
}

LLVM IR (-O2):
@.str = [6 x i8] c"<res>\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @reserved_or_num(i8* returned %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, %3
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %10
8: ; preds = %4
%9 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %2)
br label %10
10: ; preds = %8, %6
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = add nsw i32 %1, -1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %12, %10
ret i8* %0
}