#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*/ buf;

/* Variables and functions */
int atoi(char const *);
char *getenv(char *);
int /*<<< orphan*/ sanei_debug_sanei_debug_call(int /*<<< orphan*/, char *,
                                                char const *, int);
char toupper(char);
void sanei_init_debug(const char *backend, int *var) {
  char ch, buf[256] = "SANE_DEBUG_";
  const char *val;
  unsigned int i;
  *var = 0;
  for (i = 11; (ch = backend[i - 11]) != 0; ++i) {
    if (i >= sizeof(buf) - 1)
      break;
    buf[i] = toupper(ch);
  }
  buf[i] = '\0';
  val = getenv(buf);
  if (!val)
    return;
  *var = atoi(val);
  sanei_debug_sanei_debug_call(0, "Setting debug level of %s to %d.\n", backend,
                               *var);
}


x86 assembly (clang, -O0):
<sanei_init_debug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x100,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0xb,-0x12c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x12c(%rbp),%ecx
sub    $0xb,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11f3 <sanei_init_debug+0xa3>
mov    -0x12c(%rbp),%eax
cmp    $0xff,%rax
jb     11c7 <sanei_init_debug+0x77>
jmp    11f3 <sanei_init_debug+0xa3>
movsbl -0x11(%rbp),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x12c(%rbp),%eax
mov    %cl,-0x120(%rbp,%rax,1)
mov    -0x12c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x12c(%rbp)
jmp    118f <sanei_init_debug+0x3f>
mov    -0x12c(%rbp),%eax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1227 <sanei_init_debug+0xd7>
jmp    1253 <sanei_init_debug+0x103>
mov    -0x128(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
xor    %edi,%edi
lea    0xeb2(%rip),%rsi
call   1060 <sanei_debug_sanei_debug_call@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanei_init_debug>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe97(%rip),%rsi
mov    %rsp,%rdi
mov    $0x100,%edx
call   1050 <memcpy@plt>
movl   $0x0,(%r14)
mov    (%r15),%al
test   %al,%al
je     11b7 <sanei_init_debug+0x67>
mov    $0xb,%ebx
nopl   0x0(%rax)
movsbl %al,%edi
call   1040 <toupper@plt>
mov    %al,(%rsp,%rbx,1)
lea    0x1(%rbx),%rcx
movzbl -0xa(%r15,%rbx,1),%eax
test   %al,%al
je     11bc <sanei_init_debug+0x6c>
cmp    $0xfe,%rbx
mov    %rcx,%rbx
jb     1190 <sanei_init_debug+0x40>
jmp    11bc <sanei_init_debug+0x6c>
mov    $0xb,%ecx
movb   $0x0,(%rsp,%rcx,1)
mov    %rsp,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11f7 <sanei_init_debug+0xa7>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,(%r14)
lea    0xf21(%rip),%rsi
xor    %edi,%edi
mov    %r15,%rdx
mov    %eax,%ecx
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <sanei_debug_sanei_debug_call@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.sanei_init_debug.buf = [256 x i8] c"SANE_DEBUG_\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [34 x i8] c"Setting debug level of %s to %d.\0A\00"
define void @sanei_init_debug(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%9 = bitcast [256 x i8]* %6 to i8*
%10 = load i32*, i32** %4
store i32 0, i32* %10
store i32 11, i32* %8
br label %11
11: ; preds = %31, %2
%12 = load i8*, i8** %3
%13 = load i32, i32* %8
%14 = sub i32 %13, 11
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %11
%21 = load i32, i32* %8
%22 = zext i32 %21 to i64
%23 = icmp uge i64 %22, 255
br i1 %23, label %24, label %25
24: ; preds = %20
br label %34
25: ; preds = %20
%26 = load i8, i8* %5
%27 = call signext i8 @toupper(i8 signext %26)
%28 = load i32, i32* %8
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %29
store i8 %27, i8* %30
br label %31
31: ; preds = %25
%32 = load i32, i32* %8
%33 = add i32 %32, 1
store i32 %33, i32* %8
br label %11
34: ; preds = %24, %11
%35 = load i32, i32* %8
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %36
store i8 0, i8* %37
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%39 = call i8* @getenv(i8* %38)
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = icmp ne i8* %40, null
br i1 %41, label %43, label %42
42: ; preds = %34
br label %51
43: ; preds = %34
%44 = load i8*, i8** %7
%45 = call i32 @atoi(i8* %44)
%46 = load i32*, i32** %4
store i32 %45, i32* %46
%47 = load i8*, i8** %3
%48 = load i32*, i32** %4
%49 = load i32, i32* %48
%50 = call i32 @sanei_debug_sanei_debug_call(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %47, i32 %49)
br label %51
51: ; preds = %43, %42
ret void
}

LLVM IR (-O2):
@__const.sanei_init_debug.buf = [256 x i8] c"SANE_DEBUG_\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [34 x i8] c"Setting debug level of %s to %d.\0A\00"
define void @sanei_init_debug(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
store i32 0, i32* %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %12, %7 ], [ 11, %2 ]
%9 = phi i8 [ %15, %7 ], [ %5, %2 ]
%10 = tail call signext i8 @toupper(i8 signext %9)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %8
store i8 %10, i8* %11
%12 = add nuw nsw i64 %8, 1
%13 = add nsw i64 %8, -10
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
%17 = icmp ugt i64 %8, 253
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %19, label %7
19: ; preds = %7, %2
%20 = phi i64 [ 11, %2 ], [ %12, %7 ]
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i8* @getenv(i8* %4)
%23 = icmp eq i8* %22, null
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = tail call i32 @atoi(i8* %22)
store i32 %25, i32* %1
%26 = tail call i32 @sanei_debug_sanei_debug_call(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %25)
br label %27
27: ; preds = %19, %24
ret void
}