#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*/ O_RDWR;
int atoi(char *);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ smrsim_config_iot(int, int, char **);
int /*<<< orphan*/ smrsim_err_iot(int, int);
int /*<<< orphan*/ smrsim_stats_iot(int, int, char **);
int smrsim_util_print_help();
int /*<<< orphan*/ smrsim_zone_iot(int, int, char **);
int /*<<< orphan*/ smrsim_zone_rt(int, int, char **);
int main(int argc, char *argv[]) {
  int fd;
  int seq;
  char code;
  if (4 != argc && 5 != argc) {
    return smrsim_util_print_help();
  }
  code = argv[2][0];
  seq = atoi(argv[3]);
  fd = open(argv[1], O_RDWR);
  if (-1 == fd) {
    printf("Error: %s open failed\n", argv[1]);
    return -1;
  }
  switch (code) {
  case 'e':
    smrsim_err_iot(fd, seq);
    break;
  case 'z':
    smrsim_zone_iot(fd, seq, argv);
    break;
  case 's':
    smrsim_stats_iot(fd, seq, argv);
    break;
  case 'l':
    smrsim_config_iot(fd, seq, argv);
    break;
  case 'h':
    smrsim_zone_rt(fd, seq, argv);
    break;
  default:
    return smrsim_util_print_help();
  }
  close(fd);
  return 0;
}


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)
mov    $0x4,%eax
cmp    -0x8(%rbp),%eax
je     11e1 <main+0x41>
mov    $0x5,%eax
cmp    -0x8(%rbp),%eax
je     11e1 <main+0x41>
mov    $0x0,%al
call   1060 <smrsim_util_print_help@plt>
mov    %eax,-0x4(%rbp)
jmp    12ed <main+0x14d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1245 <main+0xa5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ed <main+0x14d>
movsbl -0x19(%rbp),%eax
add    $0xffffff9b,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x15,%eax
ja     12cf <main+0x12f>
mov    -0x28(%rbp),%rax
lea    0xd9a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1070 <smrsim_err_iot@plt>
jmp    12de <main+0x13e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <smrsim_zone_iot@plt>
jmp    12de <main+0x13e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   10c0 <smrsim_stats_iot@plt>
jmp    12de <main+0x13e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   10a0 <smrsim_config_iot@plt>
jmp    12de <main+0x13e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1080 <smrsim_zone_rt@plt>
jmp    12de <main+0x13e>
mov    $0x0,%al
call   1060 <smrsim_util_print_help@plt>
mov    %eax,-0x4(%rbp)
jmp    12ed <main+0x14d>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
and    $0xfffffffe,%edi
cmp    $0x4,%edi
jne    1204 <main+0x64>
mov    %rsi,%rbx
mov    0x10(%rsi),%rax
mov    0x18(%rsi),%rdi
movsbl (%rax),%ebp
call   10b0 <atoi@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1215 <main+0x75>
add    $0xffffff9b,%ebp
cmp    $0x15,%ebp
ja     1204 <main+0x64>
mov    %eax,%r15d
lea    0xe12(%rip),%rax
movslq (%rax,%rbp,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %r15d,%edi
mov    %r14d,%esi
call   1070 <smrsim_err_iot@plt>
jmp    126a <main+0xca>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <smrsim_util_print_help@plt>
mov    0x8(%rbx),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    1274 <main+0xd4>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1080 <smrsim_zone_rt@plt>
jmp    126a <main+0xca>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
call   10a0 <smrsim_config_iot@plt>
jmp    126a <main+0xca>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
call   10c0 <smrsim_stats_iot@plt>
jmp    126a <main+0xca>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1030 <smrsim_zone_iot@plt>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [23 x i8] c"Error: %s open failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 4, %9
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp ne i32 5, %12
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (...) @smrsim_util_print_help()
store i32 %15, i32* %3
br label %70
16: ; preds = %11, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
store i8 %21, i8* %8
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_RDWR
%30 = call i32 @open(i8* %28, i32 %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 -1, %31
br i1 %32, label %33, label %38
33: ; preds = %16
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %36)
store i32 -1, i32* %3
br label %70
38: ; preds = %16
%39 = load i8, i8* %8
%40 = sext i8 %39 to i32
switch i32 %40, label %65 [
i32 101, label %41
i32 122, label %45
i32 115, label %50
i32 108, label %55
i32 104, label %60
]
41: ; preds = %38
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = call i32 @smrsim_err_iot(i32 %42, i32 %43)
br label %67
45: ; preds = %38
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = load i8**, i8*** %5
%49 = call i32 @smrsim_zone_iot(i32 %46, i32 %47, i8** %48)
br label %67
50: ; preds = %38
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = load i8**, i8*** %5
%54 = call i32 @smrsim_stats_iot(i32 %51, i32 %52, i8** %53)
br label %67
55: ; preds = %38
%56 = load i32, i32* %6
%57 = load i32, i32* %7
%58 = load i8**, i8*** %5
%59 = call i32 @smrsim_config_iot(i32 %56, i32 %57, i8** %58)
br label %67
60: ; preds = %38
%61 = load i32, i32* %6
%62 = load i32, i32* %7
%63 = load i8**, i8*** %5
%64 = call i32 @smrsim_zone_rt(i32 %61, i32 %62, i8** %63)
br label %67
65: ; preds = %38
%66 = call i32 (...) @smrsim_util_print_help()
store i32 %66, i32* %3
br label %70
67: ; preds = %60, %55, %50, %45, %41
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
store i32 0, i32* %3
br label %70
70: ; preds = %67, %65, %33, %14
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [23 x i8] c"Error: %s open failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = and i32 %0, -2
%4 = icmp eq i32 %3, 4
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (...) @smrsim_util_print_help()
br label %38
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = tail call i32 @open(i8* %15, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %7
%20 = load i8*, i8** %14
%21 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %38
22: ; preds = %7
%23 = sext i8 %10 to i32
switch i32 %23, label %34 [
i32 101, label %24
i32 122, label %26
i32 115, label %28
i32 108, label %30
i32 104, label %32
]
24: ; preds = %22
%25 = tail call i32 @smrsim_err_iot(i32 %17, i32 %13)
br label %36
26: ; preds = %22
%27 = tail call i32 @smrsim_zone_iot(i32 %17, i32 %13, i8** %1)
br label %36
28: ; preds = %22
%29 = tail call i32 @smrsim_stats_iot(i32 %17, i32 %13, i8** %1)
br label %36
30: ; preds = %22
%31 = tail call i32 @smrsim_config_iot(i32 %17, i32 %13, i8** %1)
br label %36
32: ; preds = %22
%33 = tail call i32 @smrsim_zone_rt(i32 %17, i32 %13, i8** %1)
br label %36
34: ; preds = %22
%35 = tail call i32 (...) @smrsim_util_print_help()
br label %38
36: ; preds = %32, %30, %28, %26, %24
%37 = tail call i32 @close(i32 %17)
br label %38
38: ; preds = %36, %34, %19, %5
%39 = phi i32 [ %6, %5 ], [ -1, %19 ], [ %35, %34 ], [ 0, %36 ]
ret i32 %39
}