#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 atoi(char *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ startuperror(char *, char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strstr(char *, char *);
char toupper(int);
int set_level(char *section, char *name, char *value) {
  int result = 0;
  char *p;
  int i;
  if ((p = malloc(strlen(value) + 1))) {
    strcpy(p, value);
    for (i = 0; p[i]; i++)
      p[i] = toupper((int)p[i]);
    if ((result = atoi(value)) < 1) {
      if (strstr(p, "DEBUG"))
        result = 7;
      else if (strstr(p, "INFO"))
        result = 6;
      else if (strstr(p, "NOTICE"))
        result = 5;
      else if (strstr(p, "WARNING"))
        result = 4;
      else if (strstr(p, "ERROR"))
        result = 3;
      else if (strstr(p, "CRITICAL"))
        result = 2;
    }
    free(p);
  }
  if (result < 1)
    startuperror("Invalid value for %s %s: %s\n", section, name, value);
  return result;
}


x86 assembly (clang, -O0):
<set_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     132b <set_level+0x1ab>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1210 <set_level+0x90>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <toupper@plt>
mov    %al,%dl
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d2 <set_level+0x52>
mov    -0x18(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x1,%eax
jge    1322 <set_level+0x1a2>
mov    -0x28(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     124b <set_level+0xcb>
movl   $0x7,-0x1c(%rbp)
jmp    131d <set_level+0x19d>
mov    -0x28(%rbp),%rdi
lea    0xdb0(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1271 <set_level+0xf1>
movl   $0x6,-0x1c(%rbp)
jmp    1318 <set_level+0x198>
mov    -0x28(%rbp),%rdi
lea    0xd8f(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1297 <set_level+0x117>
movl   $0x5,-0x1c(%rbp)
jmp    1313 <set_level+0x193>
mov    -0x28(%rbp),%rdi
lea    0xd70(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     12bd <set_level+0x13d>
movl   $0x4,-0x1c(%rbp)
jmp    130e <set_level+0x18e>
mov    -0x28(%rbp),%rdi
lea    0xd52(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     12e3 <set_level+0x163>
movl   $0x3,-0x1c(%rbp)
jmp    1309 <set_level+0x189>
mov    -0x28(%rbp),%rdi
lea    0xd32(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1304 <set_level+0x184>
movl   $0x2,-0x1c(%rbp)
jmp    1309 <set_level+0x189>
jmp    130e <set_level+0x18e>
jmp    1313 <set_level+0x193>
jmp    1318 <set_level+0x198>
jmp    131d <set_level+0x19d>
jmp    1322 <set_level+0x1a2>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x1,-0x1c(%rbp)
jge    134d <set_level+0x1cd>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xce1(%rip),%rdi
call   1030 <startuperror@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_level>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r15
mov    %rdx,%rdi
call   1070 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     11fd <set_level+0x7d>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <strcpy@plt>
mov    (%r14),%al
test   %al,%al
je     11e6 <set_level+0x66>
mov    %r14,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1060 <toupper@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11d0 <set_level+0x50>
mov    %r12,%rdi
call   1090 <atoi@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    121d <set_level+0x9d>
mov    %r13d,%ebp
jmp    12b6 <set_level+0x136>
xor    %r13d,%r13d
lea    0xe22(%rip),%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
call   1030 <startuperror@plt>
mov    %r13d,%ebp
jmp    12be <set_level+0x13e>
mov    %rbp,%rbx
lea    0xdd9(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strstr@plt>
mov    $0x7,%ebp
test   %rax,%rax
jne    12b6 <set_level+0x136>
lea    0xdc6(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strstr@plt>
mov    $0x6,%ebp
test   %rax,%rax
jne    12b6 <set_level+0x136>
lea    0xdb2(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strstr@plt>
mov    $0x5,%ebp
test   %rax,%rax
jne    12b6 <set_level+0x136>
lea    0xda0(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strstr@plt>
mov    $0x4,%ebp
test   %rax,%rax
jne    12b6 <set_level+0x136>
lea    0xd8f(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strstr@plt>
mov    $0x3,%ebp
test   %rax,%rax
jne    12b6 <set_level+0x136>
lea    0xd7c(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strstr@plt>
mov    $0x2,%ebp
test   %rax,%rax
je     12cf <set_level+0x14f>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1040 <free@plt>
mov    %rbx,%rbp
jmp    1200 <set_level+0x80>

LLVM IR (-O0):
@.str = [6 x i8] c"DEBUG\00"
@.str.1 = [5 x i8] c"INFO\00"
@.str.2 = [7 x i8] c"NOTICE\00"
@.str.3 = [8 x i8] c"WARNING\00"
@.str.4 = [6 x i8] c"ERROR\00"
@.str.5 = [9 x i8] c"CRITICAL\00"
@.str.6 = [29 x i8] c"Invalid value for %s %s: %s\0A\00"
define i32 @set_level(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%10 = load i8*, i8** %6
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = call i8* @malloc(i64 %12)
store i8* %13, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %84
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = load i8*, i8** %6
%18 = call i32 @strcpy(i8* %16, i8* %17)
store i32 0, i32* %9
br label %19
19: ; preds = %38, %15
%20 = load i8*, i8** %8
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %41
26: ; preds = %19
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = call signext i8 @toupper(i32 %32)
%34 = load i8*, i8** %8
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %26
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %19
41: ; preds = %19
%42 = load i8*, i8** %6
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %7
%44 = icmp slt i32 %43, 1
br i1 %44, label %45, label %81
45: ; preds = %41
%46 = load i8*, i8** %8
%47 = call i64 @strstr(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %45
store i32 7, i32* %7
br label %80
50: ; preds = %45
%51 = load i8*, i8** %8
%52 = call i64 @strstr(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %50
store i32 6, i32* %7
br label %79
55: ; preds = %50
%56 = load i8*, i8** %8
%57 = call i64 @strstr(i8* %56, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 5, i32* %7
br label %78
60: ; preds = %55
%61 = load i8*, i8** %8
%62 = call i64 @strstr(i8* %61, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %60
store i32 4, i32* %7
br label %77
65: ; preds = %60
%66 = load i8*, i8** %8
%67 = call i64 @strstr(i8* %66, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %65
store i32 3, i32* %7
br label %76
70: ; preds = %65
%71 = load i8*, i8** %8
%72 = call i64 @strstr(i8* %71, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %70
store i32 2, i32* %7
br label %75
75: ; preds = %74, %70
br label %76
76: ; preds = %75, %69
br label %77
77: ; preds = %76, %64
br label %78
78: ; preds = %77, %59
br label %79
79: ; preds = %78, %54
br label %80
80: ; preds = %79, %49
br label %81
81: ; preds = %80, %41
%82 = load i8*, i8** %8
%83 = call i32 @free(i8* %82)
br label %84
84: ; preds = %81, %3
%85 = load i32, i32* %7
%86 = icmp slt i32 %85, 1
br i1 %86, label %87, label %92
87: ; preds = %84
%88 = load i8*, i8** %4
%89 = load i8*, i8** %5
%90 = load i8*, i8** %6
%91 = call i32 @startuperror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %88, i8* %89, i8* %90)
br label %92
92: ; preds = %87, %84
%93 = load i32, i32* %7
ret i32 %93
}

LLVM IR (-O2):
@.str = [6 x i8] c"DEBUG\00"
@.str.1 = [5 x i8] c"INFO\00"
@.str.2 = [7 x i8] c"NOTICE\00"
@.str.3 = [8 x i8] c"WARNING\00"
@.str.4 = [6 x i8] c"ERROR\00"
@.str.5 = [9 x i8] c"CRITICAL\00"
@.str.6 = [29 x i8] c"Invalid value for %s %s: %s\0A\00"
define i32 @set_level(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%5 = add nsw i64 %4, 1
%6 = tail call i8* @malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %48, label %8
8: ; preds = %3
%9 = tail call i32 @strcpy(i8* %6, i8* %2)
%10 = load i8, i8* %6
%11 = icmp eq i8 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %8, %12
%13 = phi i64 [ %18, %12 ], [ 0, %8 ]
%14 = phi i8 [ %20, %12 ], [ %10, %8 ]
%15 = phi i8* [ %19, %12 ], [ %6, %8 ]
%16 = sext i8 %14 to i32
%17 = tail call signext i8 @toupper(i32 %16)
store i8 %17, i8* %15
%18 = add nuw i64 %13, 1
%19 = getelementptr inbounds i8, i8* %6, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %12
22: ; preds = %12, %8
%23 = tail call i32 @atoi(i8* %2)
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %43
25: ; preds = %22
%26 = tail call i64 @strstr(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %43
28: ; preds = %25
%29 = tail call i64 @strstr(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = tail call i64 @strstr(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = tail call i64 @strstr(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = tail call i64 @strstr(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = tail call i64 @strstr(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %22, %25, %28, %31, %34, %37, %40
%44 = phi i32 [ 2, %40 ], [ 3, %37 ], [ 4, %34 ], [ 5, %31 ], [ 6, %28 ], [ 7, %25 ], [ %23, %22 ]
%45 = tail call i32 @free(i8* %6)
br label %51
46: ; preds = %40
%47 = tail call i32 @free(i8* %6)
br label %48
48: ; preds = %3, %46
%49 = phi i32 [ %23, %46 ], [ 0, %3 ]
%50 = tail call i32 @startuperror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
br label %51
51: ; preds = %43, %48
%52 = phi i32 [ %49, %48 ], [ %44, %43 ]
ret i32 %52
}