#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ merge_flash(char *, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  if (argc > 1) {
    if (strcmp(argv[1], "-bl") == 0) {
      printf("Overwrite bootloader only \n");
      merge_flash("build/bootloader/bootloader.bin", "esp32flash.bin", 0x1000,
                  0);
      system("cp esp32flash.bin ~/qemu_esp32");
      exit(0);
    }
  }
  system("dd if=/dev/zero bs=1M count=4  | tr \"\\000\" \"\\377\" >  "
         "esp32flash.bin");
  merge_flash(".pioenvs/esp-wrover-kit/partitions.bin", "esp32flash.bin",
              0x8000, 0);
  if (argc > 1) {
    merge_flash(argv[1], "esp32flash.bin", 0x10000, 0);
  } else {
    merge_flash(".pioenvs/esp-wrover-kit/firmware.bin", "esp32flash.bin",
                0x10000, 0);
  }
  system("cp esp32flash.bin ~/qemu_esp32");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11cc <main+0x7c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11c7 <main+0x77>
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7f(%rip),%rdi
lea    0xeec(%rip),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xe85(%rip),%rdi
call   1030 <system@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    11cc <main+0x7c>
lea    0xe8c(%rip),%rdi
call   1030 <system@plt>
lea    0xec4(%rip),%rdi
lea    0xeae(%rip),%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
cmpl   $0x1,-0x8(%rbp)
jle    121c <main+0xcc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe89(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
jmp    1236 <main+0xe6>
lea    0xea7(%rip),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xe03(%rip),%rdi
call   1030 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jl     119a <main+0x4a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ea <main+0x9a>
lea    0xece(%rip),%rdi
call   1040 <system@plt>
lea    0xf06(%rip),%rdi
lea    0xef0(%rip),%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
mov    0x8(%rbx),%rdi
jmp    11c7 <main+0x77>
lea    0xea2(%rip),%rdi
call   1040 <system@plt>
lea    0xeda(%rip),%rdi
lea    0xec4(%rip),%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xee7(%rip),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xe43(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe07(%rip),%rdi
lea    0xe74(%rip),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xe0d(%rip),%rdi
call   1040 <system@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"-bl\00"
@.str.1 = [28 x i8] c"Overwrite bootloader only \0A\00"
@.str.2 = [32 x i8] c"build/bootloader/bootloader.bin\00"
@.str.3 = [15 x i8] c"esp32flash.bin\00"
@.str.4 = [31 x i8] c"cp esp32flash.bin ~/qemu_esp32\00"
@.str.5 = [68 x i8] c"dd if=/dev/zero bs=1M count=4 | tr \22\\000\22 \22\\377\22 > esp32flash.bin\00"
@.str.6 = [39 x i8] c".pioenvs/esp-wrover-kit/partitions.bin\00"
@.str.7 = [37 x i8] c".pioenvs/esp-wrover-kit/firmware.bin\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 = load i32, i32* %4
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @merge_flash(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 4096, i32 0)
%17 = call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %8
br label %20
20: ; preds = %19, %2
%21 = call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 @merge_flash(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 32768, i32 0)
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 1
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @merge_flash(i8* %28, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 65536, i32 0)
br label %32
30: ; preds = %20
%31 = call i32 @merge_flash(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 65536, i32 0)
br label %32
32: ; preds = %30, %25
%33 = call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [4 x i8] c"-bl\00"
@.str.2 = [32 x i8] c"build/bootloader/bootloader.bin\00"
@.str.3 = [15 x i8] c"esp32flash.bin\00"
@.str.4 = [31 x i8] c"cp esp32flash.bin ~/qemu_esp32\00"
@.str.5 = [68 x i8] c"dd if=/dev/zero bs=1M count=4 | tr \22\\000\22 \22\\377\22 > esp32flash.bin\00"
@.str.6 = [39 x i8] c".pioenvs/esp-wrover-kit/partitions.bin\00"
@.str.7 = [37 x i8] c".pioenvs/esp-wrover-kit/firmware.bin\00"
@str = [27 x i8] c"Overwrite bootloader only \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @merge_flash(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 4096, i32 0)
%12 = tail call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %4
%15 = tail call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @merge_flash(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 32768, i32 0)
%17 = load i8*, i8** %5
br label %21
18: ; preds = %2
%19 = tail call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0))
%20 = tail call i32 @merge_flash(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 32768, i32 0)
br label %21
21: ; preds = %18, %14
%22 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), %18 ], [ %17, %14 ]
%23 = tail call i32 @merge_flash(i8* %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 65536, i32 0)
%24 = tail call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}