#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 action_add(char *);
char *getenv(char *);
int misc_dev_add();
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  int ret = 0;
  char *action_env = getenv("ACTION");
  ;
  if (action_env && !strncmp(action_env, "add", 3)) {
    char *major = getenv("MAJOR");
    if (major && *major++ == '1' && *major++ == '0' && *major++ == '\0') {
      ret = misc_dev_add();
      goto out;
    }
    char *firmware_env = getenv("FIRMWARE");
    if (firmware_env && *firmware_env != 0x00) {
      ret = action_add(firmware_env);
    }
  }
out:;
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe9c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     124d <main+0x10d>
mov    -0x20(%rbp),%rdi
lea    0xe84(%rip),%rsi
mov    $0x3,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%eax
jne    124d <main+0x10d>
lea    0xe6e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1211 <main+0xd1>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    1211 <main+0xd1>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1211 <main+0xd1>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1211 <main+0xd1>
mov    $0x0,%al
call   1060 <misc_dev_add@plt>
mov    %eax,-0x14(%rbp)
jmp    1252 <main+0x112>
lea    0xdf9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1248 <main+0x108>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1248 <main+0x108>
mov    -0x30(%rbp),%rdi
call   1040 <action_add@plt>
mov    %eax,-0x14(%rbp)
jmp    124d <main+0x10d>
jmp    1252 <main+0x112>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116a <main+0x2a>
lea    0xeae(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1050 <strncmp@plt>
test   %eax,%eax
je     116e <main+0x2e>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe96(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1190 <main+0x50>
cmpb   $0x31,(%rax)
jne    1190 <main+0x50>
cmpb   $0x30,0x1(%rax)
jne    1190 <main+0x50>
cmpb   $0x0,0x2(%rax)
je     11af <main+0x6f>
lea    0xe7a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116a <main+0x2a>
cmpb   $0x0,(%rax)
je     116a <main+0x2a>
mov    %rax,%rdi
pop    %rax
jmp    1040 <action_add@plt>
xor    %eax,%eax
pop    %rcx
jmp    1060 <misc_dev_add@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"ACTION\00"
@.str.1 = [4 x i8] c"add\00"
@.str.2 = [6 x i8] c"MAJOR\00"
@.str.3 = [9 x i8] c"FIRMWARE\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %54
13: ; preds = %2
%14 = load i8*, i8** %7
%15 = call i32 @strncmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%16 = icmp ne i32 %15, 0
br i1 %16, label %54, label %17
17: ; preds = %13
%18 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %41
21: ; preds = %17
%22 = load i8*, i8** %8
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %8
%24 = load i8, i8* %22
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 49
br i1 %26, label %27, label %41
27: ; preds = %21
%28 = load i8*, i8** %8
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %8
%30 = load i8, i8* %28
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 48
br i1 %32, label %33, label %41
33: ; preds = %27
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %8
%36 = load i8, i8* %34
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 (...) @misc_dev_add()
store i32 %40, i32* %6
br label %55
41: ; preds = %33, %27, %21, %17
%42 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i8* %42, i8** %9
%43 = load i8*, i8** %9
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load i8*, i8** %9
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i8*, i8** %9
%52 = call i32 @action_add(i8* %51)
store i32 %52, i32* %6
br label %53
53: ; preds = %50, %45, %41
br label %54
54: ; preds = %53, %13, %2
br label %55
55: ; preds = %54, %39
%56 = load i32, i32* %6
ret i32 %56
}

LLVM IR (-O2):
@.str = [7 x i8] c"ACTION\00"
@.str.1 = [4 x i8] c"add\00"
@.str.2 = [6 x i8] c"MAJOR\00"
@.str.3 = [9 x i8] c"FIRMWARE\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %32, label %5
5: ; preds = %2
%6 = tail call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %32
8: ; preds = %5
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %24, label %11
11: ; preds = %8
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 49
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 48
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %9, i64 2
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 (...) @misc_dev_add()
br label %32
24: ; preds = %18, %14, %11, %8
%25 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = load i8, i8* %25
%29 = icmp eq i8 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @action_add(i8* %25)
br label %32
32: ; preds = %5, %2, %24, %27, %30, %22
%33 = phi i32 [ 0, %5 ], [ 0, %2 ], [ %23, %22 ], [ %31, %30 ], [ 0, %27 ], [ 0, %24 ]
ret i32 %33
}