#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 */
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
scalar_t__ send_command_to_variable_server(int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int set_debug_level(int socket, int level) {
  char cmd[256];
  const char *prefix = "trick.var_debug(";
  char lev[64];
  const char *suffix = ")";
  snprintf(lev, 64, "%i", level);
  if (sizeof(cmd) < (strlen(prefix) + strlen(lev) + strlen(suffix) + 1)) {
    return -1;
  } else {
    strncpy(cmd, prefix, sizeof(cmd));
    strncat(cmd, lev, (sizeof(cmd) - strlen(cmd) - 1));
    strncat(cmd, suffix, (sizeof(cmd) - strlen(cmd) - 1));
    if (send_command_to_variable_server(socket, cmd) < 0) {
      return -1;
    } else {
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<set_debug_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe98(%rip),%rax
mov    %rax,-0x118(%rbp)
lea    0xe9b(%rip),%rax
mov    %rax,-0x168(%rbp)
lea    -0x160(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x40,%esi
lea    0xe80(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x118(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x170(%rbp)
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x170(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x16c(%rbp)
mov    -0x168(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x16c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    $0x100,%eax
cmp    %rcx,%rax
jae    11fc <set_debug_level+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d8 <set_debug_level+0x188>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x190(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x188(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x190(%rbp),%rdi
mov    -0x188(%rbp),%rsi
movslq %eax,%rcx
mov    $0x100,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1060 <strncat@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x180(%rbp)
mov    -0x168(%rbp),%rax
mov    %rax,-0x178(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x180(%rbp),%rdi
mov    -0x178(%rbp),%rsi
movslq %eax,%rcx
mov    $0x100,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1060 <strncat@plt>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
call   1070 <send_command_to_variable_server@plt>
cmp    $0x0,%rax
jge    12d1 <set_debug_level+0x181>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d8 <set_debug_level+0x188>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_debug_level>:
push   %rbp
push   %r14
push   %rbx
sub    $0x140,%rsp
mov    %esi,%ecx
mov    %edi,%r14d
lea    0xeac(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1050 <snprintf@plt>
lea    0xe82(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe7b(%rip),%rdi
call   1040 <strlen@plt>
add    %ebp,%ebx
lea    (%rax,%rbx,1),%ecx
add    $0xffffff00,%ecx
mov    $0xffffffff,%eax
cmp    $0xfffffeff,%ecx
jb     1215 <set_debug_level+0xc5>
lea    0xe46(%rip),%rsi
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0xff,%ebp
mov    $0xff,%edx
sub    %eax,%edx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
lea    0xe15(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <strncat@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1070 <send_command_to_variable_server@plt>
sar    $0x3f,%rax
add    $0x140,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"trick.var_debug(\00"
@.str.1 = [2 x i8] c")\00"
@.str.2 = [3 x i8] c"%i\00"
define i32 @set_debug_level(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca [64 x i8]
%9 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%11 = load i32, i32* %5
%12 = call i32 @snprintf(i8* %10, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %14, %16
%18 = load i8*, i8** %9
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %17, %19
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = icmp ult i64 256, %22
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 -1, i32* %3
br label %53
25: ; preds = %2
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %7
%28 = call i32 @strncpy(i8* %26, i8* %27, i32 256)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
%34 = sub i64 256, %33
%35 = sub i64 %34, 1
%36 = trunc i64 %35 to i32
%37 = call i32 @strncat(i8* %29, i8* %30, i32 %36)
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%39 = load i8*, i8** %9
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = sext i32 %41 to i64
%43 = sub i64 256, %42
%44 = sub i64 %43, 1
%45 = trunc i64 %44 to i32
%46 = call i32 @strncat(i8* %38, i8* %39, i32 %45)
%47 = load i32, i32* %4
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%49 = call i64 @send_command_to_variable_server(i32 %47, i8* %48)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %25
store i32 -1, i32* %3
br label %53
52: ; preds = %25
store i32 0, i32* %3
br label %53
53: ; preds = %52, %51, %24
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [17 x i8] c"trick.var_debug(\00"
@.str.1 = [2 x i8] c")\00"
@.str.2 = [3 x i8] c"%i\00"
define i32 @set_debug_level(i32 %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%8 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @strlen(i8* %6)
%10 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = add i32 %8, -256
%12 = add i32 %11, %9
%13 = add i32 %12, %10
%14 = icmp ult i32 %13, -257
br i1 %14, label %26, label %15
15: ; preds = %2
%16 = call i32 @strncpy(i8* %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 256)
%17 = call i32 @strlen(i8* %5)
%18 = sub i32 255, %17
%19 = call i32 @strncat(i8* %5, i8* %6, i32 %18)
%20 = call i32 @strlen(i8* %5)
%21 = sub i32 255, %20
%22 = call i32 @strncat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = call i64 @send_command_to_variable_server(i32 %0, i8* %5)
%24 = ashr i64 %23, 63
%25 = trunc i64 %24 to i32
br label %26
26: ; preds = %15, %2
%27 = phi i32 [ -1, %2 ], [ %25, %15 ]
ret i32 %27
}