#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*/ add_output(char *);
int atoi(char *);
int get_search_depth();
int /*<<< orphan*/ set_output_error();
int /*<<< orphan*/ set_search_depth(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
void gtp_level(int gtp_argc, char gtp_argv[][20]) {
  int level;
  char output[2];
  if (gtp_argc == 0) {
    snprintf(output, 2, "%d", get_search_depth());
    add_output(output);
    return;
  }
  level = atoi(gtp_argv[0]);
  if (level < 0 || level > 9) {
    set_output_error();
    add_output("invalid level");
    return;
  }
  set_search_depth(level);
  return;
}


x86 assembly (clang, -O0):
<gtp_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11ad <gtp_level+0x4d>
lea    -0x16(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <get_search_depth@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%ecx
mov    $0x2,%esi
lea    0xe66(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x16(%rbp),%rdi
call   1080 <add_output@plt>
jmp    11ed <gtp_level+0x8d>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11cd <gtp_level+0x6d>
cmpl   $0x9,-0x14(%rbp)
jle    11e5 <gtp_level+0x85>
mov    $0x0,%al
call   1050 <set_output_error@plt>
lea    0xe28(%rip),%rdi
call   1080 <add_output@plt>
jmp    11ed <gtp_level+0x8d>
mov    -0x14(%rbp),%edi
call   1060 <set_search_depth@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtp_level>:
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     118e <gtp_level+0x2e>
mov    %rsi,%rdi
call   1070 <atoi@plt>
cmp    $0xa,%eax
jb     11be <gtp_level+0x5e>
xor    %eax,%eax
call   1050 <set_output_error@plt>
lea    0xe7f(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1080 <add_output@plt>
xor    %eax,%eax
call   1030 <get_search_depth@plt>
lea    0xe64(%rip),%rdx
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1080 <add_output@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    %eax,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <set_search_depth@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [14 x i8] c"invalid level\00"
define void @gtp_level(i32 %0, [20 x i8]* nocapture %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 (...) @get_search_depth()
%8 = call i32 @snprintf(i8* %4, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @add_output(i8* %4)
br label %19
10: ; preds = %2
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp ugt i32 %12, 9
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 (...) @set_output_error()
%16 = tail call i32 @add_output(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %19
17: ; preds = %10
%18 = tail call i32 @set_search_depth(i32 %12)
br label %19
19: ; preds = %17, %14, %6
ret void
}