#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*/ _dbg(char *, ...);
int erase();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ init();
int load(char *);
char *read_datafs_from_flash();
char *read_file(char *, int *);
int save();
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write_file(char *, char *, int);
int /*<<< orphan*/ write_flash(char *);
int main(int argc, char **argv) {
  char *filename = "-";
  char *optarg = NULL;
  char *optarg1 = NULL;
  char *optarg2 = NULL;
  char *optarg3 = NULL;
  int result = 0;
  if (0)
    _dbg("starting(): argc=%d\n", argc);
  init();
  if (0)
    _dbg("argc:%d, argv[0]=%s, argv[1]=%s, argv[2]=%s\n", argc, argv[0],
         argv[1], argv[2]);
  if (argc >= 2) {
    if (argc == 3)
      filename = optarg = argv[2];
    if (argc == 5) {
      optarg1 = argv[2];
      optarg2 = argv[3];
      optarg3 = argv[4];
    }
    if (0)
      _dbg("filename=%s\n", filename);
    if (!strcmp(argv[1], "read_datafs")) {
      char *buf = read_datafs_from_flash();
      write_file(filename, buf, (1024 * 16));
      free(buf);
    } else if (!strcmp(argv[1], "write_datafs")) {
      int size = 0;
      char *buf = read_file(filename, &size);
      write_flash(buf);
      free(buf);
    } else if (!strcmp(argv[1], "save")) {
      result = save();
    } else if (!strcmp(argv[1], "load")) {
      result = load(optarg);
    } else if (!strcmp(argv[1], "erase")) {
      result = erase();
    } else
      usage();
  } else
    usage();
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe33(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    $0x0,%al
call   10a0 <init@plt>
cmpl   $0x2,-0x8(%rbp)
jl     138b <main+0x1db>
cmpl   $0x3,-0x8(%rbp)
jne    1223 <main+0x73>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
cmpl   $0x5,-0x8(%rbp)
jne    1251 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda2(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    1299 <main+0xe9>
mov    $0x0,%al
call   1050 <read_datafs_from_flash@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    $0x4000,%edx
call   1060 <write_file@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
jmp    1386 <main+0x1d6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd66(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    12e5 <main+0x135>
movl   $0x0,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
call   10b0 <read_file@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <write_flash@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
jmp    1381 <main+0x1d1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd27(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    1311 <main+0x161>
mov    $0x0,%al
call   1080 <save@plt>
mov    %eax,-0x3c(%rbp)
jmp    137c <main+0x1cc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd00(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    133f <main+0x18f>
mov    -0x20(%rbp),%rdi
call   10d0 <load@plt>
mov    %eax,-0x3c(%rbp)
jmp    1377 <main+0x1c7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcd7(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    136b <main+0x1bb>
mov    $0x0,%al
call   1070 <erase@plt>
mov    %eax,-0x3c(%rbp)
jmp    1372 <main+0x1c2>
mov    $0x0,%al
call   10c0 <usage@plt>
jmp    1377 <main+0x1c7>
jmp    137c <main+0x1cc>
jmp    1381 <main+0x1d1>
jmp    1386 <main+0x1d6>
jmp    1392 <main+0x1e2>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    -0x3c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   10a0 <init@plt>
cmp    $0x2,%ebp
jl     1247 <main+0x97>
cmp    $0x3,%ebp
jne    11d6 <main+0x26>
mov    0x10(%rbx),%r14
mov    %r14,%r15
jmp    11e0 <main+0x30>
lea    0xe23(%rip),%r15
xor    %r14d,%r14d
mov    0x8(%rbx),%rbx
lea    0xe17(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     1250 <main+0xa0>
lea    0xe10(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     126c <main+0xbc>
lea    0xe0a(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     12a1 <main+0xf1>
lea    0xdf8(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     12b2 <main+0x102>
lea    0xdea(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     12c4 <main+0x114>
xor    %eax,%eax
call   10c0 <usage@plt>
jmp    1294 <main+0xe4>
xor    %eax,%eax
call   1050 <read_datafs_from_flash@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x4000,%edx
call   1060 <write_file@plt>
jmp    128c <main+0xdc>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %r15,%rdi
call   10b0 <read_file@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <write_flash@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <save@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10d0 <load@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <erase@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [12 x i8] c"read_datafs\00"
@.str.2 = [13 x i8] c"write_datafs\00"
@.str.3 = [5 x i8] c"save\00"
@.str.4 = [5 x i8] c"load\00"
@.str.5 = [6 x i8] c"erase\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
store i32 0, i32* %11
%15 = call i32 (...) @init()
%16 = load i32, i32* %4
%17 = icmp sge i32 %16, 2
br i1 %17, label %18, label %96
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 3
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
store i8* %24, i8** %7
store i8* %24, i8** %6
br label %25
25: ; preds = %21, %18
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 5
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
store i8* %31, i8** %8
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
store i8* %34, i8** %9
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 4
%37 = load i8*, i8** %36
store i8* %37, i8** %10
br label %38
38: ; preds = %28, %25
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %51, label %44
44: ; preds = %38
%45 = call i8* (...) @read_datafs_from_flash()
store i8* %45, i8** %12
%46 = load i8*, i8** %6
%47 = load i8*, i8** %12
%48 = call i32 @write_file(i8* %46, i8* %47, i32 16384)
%49 = load i8*, i8** %12
%50 = call i32 @free(i8* %49)
br label %95
51: ; preds = %38
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %64, label %57
57: ; preds = %51
store i32 0, i32* %13
%58 = load i8*, i8** %6
%59 = call i8* @read_file(i8* %58, i32* %13)
store i8* %59, i8** %14
%60 = load i8*, i8** %14
%61 = call i32 @write_flash(i8* %60)
%62 = load i8*, i8** %14
%63 = call i32 @free(i8* %62)
br label %94
64: ; preds = %51
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = call i32 @strcmp(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%69 = icmp ne i32 %68, 0
br i1 %69, label %72, label %70
70: ; preds = %64
%71 = call i32 (...) @save()
store i32 %71, i32* %11
br label %93
72: ; preds = %64
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 1
%75 = load i8*, i8** %74
%76 = call i32 @strcmp(i8* %75, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%77 = icmp ne i32 %76, 0
br i1 %77, label %81, label %78
78: ; preds = %72
%79 = load i8*, i8** %7
%80 = call i32 @load(i8* %79)
store i32 %80, i32* %11
br label %92
81: ; preds = %72
%82 = load i8**, i8*** %5
%83 = getelementptr inbounds i8*, i8** %82, i64 1
%84 = load i8*, i8** %83
%85 = call i32 @strcmp(i8* %84, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%86 = icmp ne i32 %85, 0
br i1 %86, label %89, label %87
87: ; preds = %81
%88 = call i32 (...) @erase()
store i32 %88, i32* %11
br label %91
89: ; preds = %81
%90 = call i32 (...) @usage()
br label %91
91: ; preds = %89, %87
br label %92
92: ; preds = %91, %78
br label %93
93: ; preds = %92, %70
br label %94
94: ; preds = %93, %57
br label %95
95: ; preds = %94, %44
br label %98
96: ; preds = %2
%97 = call i32 (...) @usage()
br label %98
98: ; preds = %96, %95
%99 = load i32, i32* %11
ret i32 %99
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [12 x i8] c"read_datafs\00"
@.str.2 = [13 x i8] c"write_datafs\00"
@.str.3 = [5 x i8] c"save\00"
@.str.4 = [5 x i8] c"load\00"
@.str.5 = [6 x i8] c"erase\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = tail call i32 (...) @init()
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %47
6: ; preds = %2
%7 = icmp eq i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
br label %11
11: ; preds = %8, %6
%12 = phi i8* [ %10, %8 ], [ null, %6 ]
%13 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %6 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = tail call i8* (...) @read_datafs_from_flash()
%20 = tail call i32 @write_file(i8* %13, i8* %19, i32 16384)
%21 = tail call i32 @free(i8* %19)
br label %49
22: ; preds = %11
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%27 = call i8* @read_file(i8* %13, i32* %3)
%28 = call i32 @write_flash(i8* %27)
%29 = call i32 @free(i8* %27)
br label %49
30: ; preds = %22
%31 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 (...) @save()
br label %49
35: ; preds = %30
%36 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i32 @load(i8* %12)
br label %49
40: ; preds = %35
%41 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = tail call i32 (...) @erase()
br label %49
45: ; preds = %40
%46 = tail call i32 (...) @usage()
br label %49
47: ; preds = %2
%48 = tail call i32 (...) @usage()
br label %49
49: ; preds = %18, %33, %43, %45, %38, %25, %47
%50 = phi i32 [ 0, %45 ], [ %44, %43 ], [ %39, %38 ], [ %34, %33 ], [ 0, %25 ], [ 0, %18 ], [ 0, %47 ]
ret i32 %50
}