#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*/ hal_set_debug_level(int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
void debug_level(char *ptr) {
  int debug_level = 0;
  if (ptr) {
    sscanf(ptr, "%i", &debug_level);
  }
  hal_set_debug_level((((debug_level) > (2))
                           ? (2)
                           : (((debug_level) < (0)) ? (0) : (debug_level))));
}


x86 assembly (clang, -O0):
<debug_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1152 <debug_level+0x32>
mov    -0x8(%rbp),%rdi
lea    0xeb7(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <sscanf@plt>
cmpl   $0x2,-0xc(%rbp)
jle    1169 <debug_level+0x49>
mov    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    1189 <debug_level+0x69>
cmpl   $0x0,-0xc(%rbp)
jge    117d <debug_level+0x5d>
xor    %eax,%eax
mov    %eax,-0x14(%rbp)
jmp    1183 <debug_level+0x63>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <hal_set_debug_level@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_level>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
xor    %ebx,%ebx
test   %rdi,%rdi
je     115c <debug_level+0x3c>
lea    0xec5(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1030 <sscanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    115c <debug_level+0x3c>
mov    $0x2,%edi
mov    $0x1,%ebx
cmp    $0x1,%eax
jne    115e <debug_level+0x3e>
mov    %ebx,%edi
call   1040 <hal_set_debug_level@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
define void @debug_level(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %9
9: ; preds = %6, %1
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %9
br label %21
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
br label %19
17: ; preds = %13
%18 = load i32, i32* %3
br label %19
19: ; preds = %17, %16
%20 = phi i32 [ 0, %16 ], [ %18, %17 ]
br label %21
21: ; preds = %19, %12
%22 = phi i32 [ 2, %12 ], [ %20, %19 ]
%23 = call i32 @hal_set_debug_level(i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define void @debug_level(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = icmp eq i8* %0, null
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = icmp eq i32 %7, 1
br i1 %10, label %11, label %13
11: ; preds = %1, %5, %9
%12 = phi i32 [ 1, %9 ], [ 0, %5 ], [ 0, %1 ]
br label %13
13: ; preds = %9, %11
%14 = phi i32 [ %12, %11 ], [ 2, %9 ]
%15 = call i32 @hal_set_debug_level(i32 %14)
ret void
}