#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 /*<<< orphan*/ board_flash_get_datafs_size();
int erase();
char *flash_read_datafs();
int /*<<< orphan*/ flash_write_datafs(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ init();
int load(char *);
char *read_file(char *, int *);
int save();
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write_file(char *, char *, int /*<<< orphan*/);
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 = flash_read_datafs();
      write_file(filename, buf, board_flash_get_datafs_size());
      free(buf);
    } else if (!strcmp(argv[1], "write_datafs")) {
      int size = 0;
      char *buf = read_file(filename, &size);
      flash_write_datafs(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    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe23(%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   1080 <init@plt>
cmpl   $0x2,-0x8(%rbp)
jl     13af <main+0x1ef>
cmpl   $0x3,-0x8(%rbp)
jne    1233 <main+0x73>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
cmpl   $0x5,-0x8(%rbp)
jne    1261 <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    0xd92(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12bd <main+0xfd>
mov    $0x0,%al
call   10a0 <flash_read_datafs@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   10e0 <board_flash_get_datafs_size@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1040 <write_file@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
jmp    13aa <main+0x1ea>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd42(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1309 <main+0x149>
movl   $0x0,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
call   1090 <read_file@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   10d0 <flash_write_datafs@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
jmp    13a5 <main+0x1e5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd03(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1335 <main+0x175>
mov    $0x0,%al
call   1060 <save@plt>
mov    %eax,-0x3c(%rbp)
jmp    13a0 <main+0x1e0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcdc(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1363 <main+0x1a3>
mov    -0x20(%rbp),%rdi
call   10c0 <load@plt>
mov    %eax,-0x3c(%rbp)
jmp    139b <main+0x1db>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcb3(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    138f <main+0x1cf>
mov    $0x0,%al
call   1050 <erase@plt>
mov    %eax,-0x3c(%rbp)
jmp    1396 <main+0x1d6>
mov    $0x0,%al
call   10b0 <usage@plt>
jmp    139b <main+0x1db>
jmp    13a0 <main+0x1e0>
jmp    13a5 <main+0x1e5>
jmp    13aa <main+0x1ea>
jmp    13b6 <main+0x1f6>
mov    $0x0,%al
call   10b0 <usage@plt>
mov    -0x3c(%rbp),%eax
add    $0x70,%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   1080 <init@plt>
cmp    $0x2,%ebp
jl     1263 <main+0xa3>
cmp    $0x3,%ebp
jne    11ea <main+0x2a>
mov    0x10(%rbx),%r14
mov    %r14,%r15
jmp    11f4 <main+0x34>
lea    0xe0f(%rip),%r15
xor    %r14d,%r14d
mov    0x8(%rbx),%rbx
lea    0xe03(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     126c <main+0xac>
lea    0xdfc(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     128c <main+0xcc>
lea    0xdf6(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     12c1 <main+0x101>
lea    0xde4(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     12d2 <main+0x112>
lea    0xdd2(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     12e4 <main+0x124>
xor    %eax,%eax
call   10b0 <usage@plt>
jmp    12b4 <main+0xf4>
xor    %eax,%eax
call   10a0 <flash_read_datafs@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10e0 <board_flash_get_datafs_size@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write_file@plt>
jmp    12ac <main+0xec>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %r15,%rdi
call   1090 <read_file@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10d0 <flash_write_datafs@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    1060 <save@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <load@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <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 %97
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 %52, label %44
44: ; preds = %38
%45 = call i8* (...) @flash_read_datafs()
store i8* %45, i8** %12
%46 = load i8*, i8** %6
%47 = load i8*, i8** %12
%48 = call i32 (...) @board_flash_get_datafs_size()
%49 = call i32 @write_file(i8* %46, i8* %47, i32 %48)
%50 = load i8*, i8** %12
%51 = call i32 @free(i8* %50)
br label %96
52: ; preds = %38
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @strcmp(i8* %55, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%57 = icmp ne i32 %56, 0
br i1 %57, label %65, label %58
58: ; preds = %52
store i32 0, i32* %13
%59 = load i8*, i8** %6
%60 = call i8* @read_file(i8* %59, i32* %13)
store i8* %60, i8** %14
%61 = load i8*, i8** %14
%62 = call i32 @flash_write_datafs(i8* %61)
%63 = load i8*, i8** %14
%64 = call i32 @free(i8* %63)
br label %95
65: ; preds = %52
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = call i32 @strcmp(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%70 = icmp ne i32 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %65
%72 = call i32 (...) @save()
store i32 %72, i32* %11
br label %94
73: ; preds = %65
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = call i32 @strcmp(i8* %76, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%78 = icmp ne i32 %77, 0
br i1 %78, label %82, label %79
79: ; preds = %73
%80 = load i8*, i8** %7
%81 = call i32 @load(i8* %80)
store i32 %81, i32* %11
br label %93
82: ; preds = %73
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 1
%85 = load i8*, i8** %84
%86 = call i32 @strcmp(i8* %85, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%87 = icmp ne i32 %86, 0
br i1 %87, label %90, label %88
88: ; preds = %82
%89 = call i32 (...) @erase()
store i32 %89, i32* %11
br label %92
90: ; preds = %82
%91 = call i32 (...) @usage()
br label %92
92: ; preds = %90, %88
br label %93
93: ; preds = %92, %79
br label %94
94: ; preds = %93, %71
br label %95
95: ; preds = %94, %58
br label %96
96: ; preds = %95, %44
br label %99
97: ; preds = %2
%98 = call i32 (...) @usage()
br label %99
99: ; preds = %97, %96
%100 = load i32, i32* %11
ret i32 %100
}

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 %48
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 %23
18: ; preds = %11
%19 = tail call i8* (...) @flash_read_datafs()
%20 = tail call i32 (...) @board_flash_get_datafs_size()
%21 = tail call i32 @write_file(i8* %13, i8* %19, i32 %20)
%22 = tail call i32 @free(i8* %19)
br label %50
23: ; preds = %11
%24 = 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))
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%28 = call i8* @read_file(i8* %13, i32* %3)
%29 = call i32 @flash_write_datafs(i8* %28)
%30 = call i32 @free(i8* %28)
br label %50
31: ; preds = %23
%32 = 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))
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 (...) @save()
br label %50
36: ; preds = %31
%37 = 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))
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = tail call i32 @load(i8* %12)
br label %50
41: ; preds = %36
%42 = 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))
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i32 (...) @erase()
br label %50
46: ; preds = %41
%47 = tail call i32 (...) @usage()
br label %50
48: ; preds = %2
%49 = tail call i32 (...) @usage()
br label %50
50: ; preds = %18, %34, %44, %46, %39, %26, %48
%51 = phi i32 [ 0, %46 ], [ %45, %44 ], [ %40, %39 ], [ %35, %34 ], [ 0, %26 ], [ 0, %18 ], [ 0, %48 ]
ret i32 %51
}