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

/* Variables and functions */
char *get_cmdline(char const *, unsigned int *);
int /*<<< orphan*/ printf(char *);
char get_modman_mode() {
  const char find_param[] = "modman.mode=";
  char *param_str;
  unsigned int cmdlen;
  param_str = get_cmdline(find_param, &cmdlen);
  if (param_str == NULL) {
    return 'a';
  }
  if (cmdlen != sizeof(find_param)) {
    goto invalid;
  }
  param_str += (cmdlen - 1);
  switch (*param_str) {
  case 'a':
    return 'a';
  case 'w':
    return 'w';
  case 'i':
    return 'i';
  default:
    return 'n';
  }
invalid:
  printf("modman: bad kernel cmdline param, defaulting to auto mode.\n");
  printf("usage:\n\n");
  printf("       auto mode: modman.mode=a\n");
  printf("  whitelist mode: modman.mode=w\n");
  printf("interactive mode: modman.mode=i\n");
  printf("       null mode: modman.mode=n\n");
  return 'a';
}


x86 assembly (clang, -O0):
<get_modman_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x6(%rbp)
mov    0xeca(%rip),%al
mov    %al,-0x2(%rbp)
lea    -0xe(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <get_cmdline@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116a <get_modman_mode+0x4a>
movb   $0x61,-0x1(%rbp)
jmp    1237 <get_modman_mode+0x117>
mov    -0x1c(%rbp),%eax
cmp    $0xd,%rax
je     117c <get_modman_mode+0x5c>
jmp    11eb <get_modman_mode+0xcb>
mov    -0x1c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    -0x18(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
sub    $0x61,%eax
je     11c7 <get_modman_mode+0xa7>
jmp    11a5 <get_modman_mode+0x85>
mov    -0x20(%rbp),%eax
sub    $0x69,%eax
je     11d9 <get_modman_mode+0xb9>
jmp    11b6 <get_modman_mode+0x96>
mov    -0x20(%rbp),%eax
sub    $0x77,%eax
je     11d0 <get_modman_mode+0xb0>
jmp    11e2 <get_modman_mode+0xc2>
movb   $0x61,-0x1(%rbp)
jmp    1237 <get_modman_mode+0x117>
movb   $0x77,-0x1(%rbp)
jmp    1237 <get_modman_mode+0x117>
movb   $0x69,-0x1(%rbp)
jmp    1237 <get_modman_mode+0x117>
movb   $0x6e,-0x1(%rbp)
jmp    1237 <get_modman_mode+0x117>
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
movb   $0x61,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_modman_mode>:
push   %rbx
sub    $0x20,%rsp
movabs $0x3d65646f6d2e6e,%rax
mov    %rax,0x15(%rsp)
movabs $0x6d2e6e616d646f6d,%rax
6e 2e 6d
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1040 <get_cmdline@plt>
mov    $0x61,%bl
test   %rax,%rax
je     11c7 <get_modman_mode+0xa7>
cmpl   $0xd,0xc(%rsp)
jne    1177 <get_modman_mode+0x57>
movsbl 0xc(%rax),%eax
cmp    $0x61,%eax
je     11c7 <get_modman_mode+0xa7>
cmp    $0x69,%eax
je     11c1 <get_modman_mode+0xa1>
cmp    $0x77,%eax
jne    11c5 <get_modman_mode+0xa5>
mov    $0x77,%bl
jmp    11c7 <get_modman_mode+0xa7>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
jmp    11c7 <get_modman_mode+0xa7>
mov    $0x69,%bl
jmp    11c7 <get_modman_mode+0xa7>
mov    $0x6e,%bl
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.get_modman_mode.find_param = [13 x i8] c"modman.mode=\00"
@.str = [60 x i8] c"modman: bad kernel cmdline param, defaulting to auto mode.\0A\00"
@.str.1 = [9 x i8] c"usage:\0A\0A\00"
@.str.2 = [33 x i8] c" auto mode: modman.mode=a\0A\00"
@.str.3 = [33 x i8] c" whitelist mode: modman.mode=w\0A\00"
@.str.4 = [33 x i8] c"interactive mode: modman.mode=i\0A\00"
@.str.5 = [33 x i8] c" null mode: modman.mode=n\0A\00"
define signext i8 @get_modman_mode() {
%1 = alloca i8
%2 = alloca [13 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast [13 x i8]* %2 to i8*
%6 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%7 = call i8* @get_cmdline(i8* %6, i32* %4)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
store i8 97, i8* %1
br label %36
11: ; preds = %0
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = icmp ne i64 %13, 13
br i1 %14, label %15, label %16
15: ; preds = %11
br label %29
16: ; preds = %11
%17 = load i32, i32* %4
%18 = sub i32 %17, 1
%19 = load i8*, i8** %3
%20 = zext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %3
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
switch i32 %24, label %28 [
i32 97, label %25
i32 119, label %26
i32 105, label %27
]
25: ; preds = %16
store i8 97, i8* %1
br label %36
26: ; preds = %16
store i8 119, i8* %1
br label %36
27: ; preds = %16
store i8 105, i8* %1
br label %36
28: ; preds = %16
store i8 110, i8* %1
br label %36
29: ; preds = %15
%30 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
store i8 97, i8* %1
br label %36
36: ; preds = %29, %28, %27, %26, %25, %10
%37 = load i8, i8* %1
ret i8 %37
}

LLVM IR (-O2):
@__const.get_modman_mode.find_param = [13 x i8] c"modman.mode=\00"
@str = [59 x i8] c"modman: bad kernel cmdline param, defaulting to auto mode.\00"
@str.6 = [8 x i8] c"usage:\0A\00"
@str.7 = [32 x i8] c" auto mode: modman.mode=a\00"
@str.8 = [32 x i8] c" whitelist mode: modman.mode=w\00"
@str.9 = [32 x i8] c"interactive mode: modman.mode=i\00"
@str.10 = [32 x i8] c" null mode: modman.mode=n\00"
define signext i8 @get_modman_mode() {
%1 = alloca [13 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = call i8* @get_cmdline(i8* %3, i32* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %24, label %7
7: ; preds = %0
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 13
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %5, i64 12
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %16 [
i32 97, label %24
i32 119, label %14
i32 105, label %15
]
14: ; preds = %10
br label %24
15: ; preds = %10
br label %24
16: ; preds = %10
br label %24
17: ; preds = %7
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.8, i64 0, i64 0))
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.9, i64 0, i64 0))
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.10, i64 0, i64 0))
br label %24
24: ; preds = %10, %0, %17, %16, %15, %14
%25 = phi i8 [ 97, %17 ], [ 110, %16 ], [ 105, %15 ], [ 119, %14 ], [ 97, %0 ], [ 97, %10 ]
ret i8 %25
}