#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*/ boundary(char *);
int /*<<< orphan*/ c2_init();
int /*<<< orphan*/ c2_reset();
int /*<<< orphan*/ do_flash(char *);
int /*<<< orphan*/ dump_flash(int);
int /*<<< orphan*/ erase_flash();
int /*<<< orphan*/ identify();
int /*<<< orphan*/ protect();
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  c2_init();
  identify();
  switch (argc) {
  case 1:
    break;
  case 2:
    if (!strcmp(argv[1], "-d"))
      dump_flash(0x4000);
    else if (!strcmp(argv[1], "-e"))
      erase_flash();
    else if (*argv[1] == '-')
      usage(*argv);
    else {
      do_flash(argv[1]);
      identify();
    }
    break;
  case 3:
    if (!strcmp(argv[1], "-p")) {
      if (*argv[2] == '-')
        usage(*argv);
      do_flash(argv[2]);
      protect();
      identify();
      break;
    }
    if (strcmp(argv[1], "-b"))
      usage(*argv);
    boundary(argv[2]);
    break;
  default:
    usage(*argv);
  }
  c2_reset();
  return 0;
}


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)
xor    %eax,%eax
mov    %al,-0x15(%rbp)
call   1040 <c2_init@plt>
mov    -0x15(%rbp),%al
call   1090 <identify@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     11fe <main+0x5e>
jmp    11dc <main+0x3c>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     1203 <main+0x63>
jmp    11ed <main+0x4d>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     12a0 <main+0x100>
jmp    1338 <main+0x198>
jmp    1344 <main+0x1a4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdee(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    122f <main+0x8f>
mov    $0x4000,%edi
call   1060 <dump_flash@plt>
jmp    129b <main+0xfb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc5(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1258 <main+0xb8>
mov    $0x0,%al
call   1070 <erase_flash@plt>
jmp    1296 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    127d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
jmp    1291 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <do_flash@plt>
mov    $0x0,%al
call   1090 <identify@plt>
jmp    1296 <main+0xf6>
jmp    129b <main+0xfb>
jmp    1344 <main+0x1a4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd57(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12fd <main+0x15d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    12dd <main+0x13d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <do_flash@plt>
mov    $0x0,%al
call   1080 <protect@plt>
mov    $0x0,%al
call   1090 <identify@plt>
jmp    1344 <main+0x1a4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcfd(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     1326 <main+0x186>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <boundary@plt>
jmp    1344 <main+0x1a4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    $0x0,%al
call   10c0 <c2_reset@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <c2_init@plt>
xor    %eax,%eax
call   1090 <identify@plt>
cmp    $0x1,%ebp
je     1293 <main+0xf3>
cmp    $0x3,%ebp
je     120f <main+0x6f>
cmp    $0x2,%ebp
jne    1202 <main+0x62>
mov    0x8(%rbx),%r14
lea    0xe2b(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     124c <main+0xac>
lea    0xe1b(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     127b <main+0xdb>
cmpb   $0x2d,(%r14)
jne    1284 <main+0xe4>
mov    (%rbx),%rdi
call   10a0 <usage@plt>
jmp    1293 <main+0xf3>
mov    0x8(%rbx),%rbp
lea    0xdec(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1258 <main+0xb8>
lea    0xddc(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1241 <main+0xa1>
mov    (%rbx),%rdi
call   10a0 <usage@plt>
mov    0x10(%rbx),%rdi
call   10b0 <boundary@plt>
jmp    1293 <main+0xf3>
mov    $0x4000,%edi
call   1060 <dump_flash@plt>
jmp    1293 <main+0xf3>
mov    0x10(%rbx),%rdi
cmpb   $0x2d,(%rdi)
jne    126d <main+0xcd>
mov    (%rbx),%rdi
call   10a0 <usage@plt>
mov    0x10(%rbx),%rdi
call   1030 <do_flash@plt>
xor    %eax,%eax
call   1080 <protect@plt>
jmp    128c <main+0xec>
xor    %eax,%eax
call   1070 <erase_flash@plt>
jmp    1293 <main+0xf3>
mov    %r14,%rdi
call   1030 <do_flash@plt>
xor    %eax,%eax
call   1090 <identify@plt>
xor    %eax,%eax
call   10c0 <c2_reset@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-d\00"
@.str.1 = [3 x i8] c"-e\00"
@.str.2 = [3 x i8] c"-p\00"
@.str.3 = [3 x i8] c"-b\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 (...) @c2_init()
%7 = call i32 (...) @identify()
%8 = load i32, i32* %4
switch i32 %8, label %85 [
i32 1, label %9
i32 2, label %10
i32 3, label %46
]
9: ; preds = %2
br label %89
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = call i32 @dump_flash(i32 16384)
br label %45
18: ; preds = %10
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = call i32 (...) @erase_flash()
br label %44
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 45
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = call i32 @usage(i8* %35)
br label %43
37: ; preds = %26
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @do_flash(i8* %40)
%42 = call i32 (...) @identify()
br label %43
43: ; preds = %37, %33
br label %44
44: ; preds = %43, %24
br label %45
45: ; preds = %44, %16
br label %89
46: ; preds = %2
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @strcmp(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %70, label %52
52: ; preds = %46
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 45
br i1 %58, label %59, label %63
59: ; preds = %52
%60 = load i8**, i8*** %5
%61 = load i8*, i8** %60
%62 = call i32 @usage(i8* %61)
br label %63
63: ; preds = %59, %52
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = load i8*, i8** %65
%67 = call i32 @do_flash(i8* %66)
%68 = call i32 (...) @protect()
%69 = call i32 (...) @identify()
br label %89
70: ; preds = %46
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i32 @strcmp(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %70
%77 = load i8**, i8*** %5
%78 = load i8*, i8** %77
%79 = call i32 @usage(i8* %78)
br label %80
80: ; preds = %76, %70
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 2
%83 = load i8*, i8** %82
%84 = call i32 @boundary(i8* %83)
br label %89
85: ; preds = %2
%86 = load i8**, i8*** %5
%87 = load i8*, i8** %86
%88 = call i32 @usage(i8* %87)
br label %89
89: ; preds = %85, %80, %63, %45, %9
%90 = call i32 (...) @c2_reset()
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-d\00"
@.str.1 = [3 x i8] c"-e\00"
@.str.2 = [3 x i8] c"-p\00"
@.str.3 = [3 x i8] c"-b\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @c2_init()
%4 = tail call i32 (...) @identify()
switch i32 %0, label %55 [
i32 1, label %58
i32 2, label %5
i32 3, label %26
]
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @dump_flash(i32 16384)
br label %58
12: ; preds = %5
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 (...) @erase_flash()
br label %58
17: ; preds = %12
%18 = load i8, i8* %7
%19 = icmp eq i8 %18, 45
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i8*, i8** %1
%22 = tail call i32 @usage(i8* %21)
br label %58
23: ; preds = %17
%24 = tail call i32 @do_flash(i8* %7)
%25 = tail call i32 (...) @identify()
br label %58
26: ; preds = %2
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %45
31: ; preds = %26
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 45
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i8*, i8** %1
%38 = tail call i32 @usage(i8* %37)
%39 = load i8*, i8** %32
br label %40
40: ; preds = %36, %31
%41 = phi i8* [ %39, %36 ], [ %33, %31 ]
%42 = tail call i32 @do_flash(i8* %41)
%43 = tail call i32 (...) @protect()
%44 = tail call i32 (...) @identify()
br label %58
45: ; preds = %26
%46 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %45
%49 = load i8*, i8** %1
%50 = tail call i32 @usage(i8* %49)
br label %51
51: ; preds = %48, %45
%52 = getelementptr inbounds i8*, i8** %1, i64 2
%53 = load i8*, i8** %52
%54 = tail call i32 @boundary(i8* %53)
br label %58
55: ; preds = %2
%56 = load i8*, i8** %1
%57 = tail call i32 @usage(i8* %56)
br label %58
58: ; preds = %10, %20, %23, %15, %55, %51, %40, %2
%59 = tail call i32 (...) @c2_reset()
ret i32 0
}