#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*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int i;
  fprintf(stderr, "usermodehelper: ");
  for (i = 0; i < argc; i++) {
    fprintf(stderr, "%s ", argv[i]);
  }
  fprintf(stderr, "\n");
  if (!strcmp(argv[0], "/sbin/mdev")) {
    execv(argv[0], argv);
  } else if (!strcmp(argv[0], "/sbin/modprobe")) {
    execv(argv[0], argv);
  } else if (!strcmp(argv[0], "/sbin/poweroff") ||
             !strcmp(argv[0], "/sbin/reboot")) {
    execv(argv[0], argv);
  } else {
    exit(2);
  }
  perror("exec failed");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c1 <main+0x71>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <main+0x34>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe31(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1209 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execv@plt>
jmp    129b <main+0x14b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe0b(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    123a <main+0xea>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execv@plt>
jmp    1296 <main+0x146>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xde9(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
je     1272 <main+0x122>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xddc(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1287 <main+0x137>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execv@plt>
jmp    1291 <main+0x141>
mov    $0x2,%edi
call   1060 <exit@plt>
jmp    1296 <main+0x146>
jmp    129b <main+0x14b>
lea    0xdab(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2e7b(%rip),%r14
mov    (%r14),%edi
lea    0xe91(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebx,%ebx
jle    11aa <main+0x5a>
mov    %ebx,%r13d
lea    0xe8d(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%edi
mov    (%r15,%rbx,8),%rdx
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1190 <main+0x40>
mov    (%r14),%edi
lea    0xe61(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r15),%r14
lea    0xe52(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     120a <main+0xba>
lea    0xe4a(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     120a <main+0xba>
lea    0xe46(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     120a <main+0xba>
lea    0xe42(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
jne    1230 <main+0xe0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <execv@plt>
lea    0xe31(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"usermodehelper: \00"
@.str.1 = [4 x i8] c"%s \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [11 x i8] c"/sbin/mdev\00"
@.str.4 = [15 x i8] c"/sbin/modprobe\00"
@.str.5 = [15 x i8] c"/sbin/poweroff\00"
@.str.6 = [13 x i8] c"/sbin/reboot\00"
@.str.7 = [12 x i8] c"exec failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %13
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %9
24: ; preds = %9
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %24
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = call i32 @execv(i8* %35, i8** %36)
br label %72
38: ; preds = %24
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %50, label %44
44: ; preds = %38
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %5
%49 = call i32 @execv(i8* %47, i8** %48)
br label %71
50: ; preds = %38
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 0
%53 = load i8*, i8** %52
%54 = call i32 @strcmp(i8* %53, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %50
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = call i32 @strcmp(i8* %59, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%61 = icmp ne i32 %60, 0
br i1 %61, label %68, label %62
62: ; preds = %56, %50
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 0
%65 = load i8*, i8** %64
%66 = load i8**, i8*** %5
%67 = call i32 @execv(i8* %65, i8** %66)
br label %70
68: ; preds = %56
%69 = call i32 @exit(i32 2)
unreachable
70: ; preds = %62
br label %71
71: ; preds = %70, %44
br label %72
72: ; preds = %71, %32
%73 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"usermodehelper: \00"
@.str.1 = [4 x i8] c"%s \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [11 x i8] c"/sbin/mdev\00"
@.str.4 = [15 x i8] c"/sbin/modprobe\00"
@.str.5 = [15 x i8] c"/sbin/poweroff\00"
@.str.6 = [13 x i8] c"/sbin/reboot\00"
@.str.7 = [12 x i8] c"exec failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %14, %8 ]
%10 = load i32, i32* @stderr
%11 = getelementptr inbounds i8*, i8** %1, i64 %9
%12 = load i8*, i8** %11
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %16, label %8
16: ; preds = %8, %2
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %1
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %33, label %22
22: ; preds = %16
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %22
%26 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = tail call i32 @exit(i32 2)
unreachable
33: ; preds = %25, %28, %22, %16
%34 = tail call i32 @execv(i8* %19, i8** %1)
%35 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
ret i32 1
}