#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/bootloader.bin", "esp32flash.bin",
              0x1000, 0);
  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    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xed1(%rip),%rdi
lea    0xe94(%rip),%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1236 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
jmp    1250 <main+0x100>
lea    0xeb4(%rip),%rdi
lea    0xe50(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xde9(%rip),%rdi
call   1030 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11ba <main+0x6a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe99(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1229 <main+0xd9>
lea    0xec7(%rip),%rdi
call   1040 <system@plt>
lea    0xeff(%rip),%rdi
lea    0xee9(%rip),%r14
mov    %r14,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xf09(%rip),%rdi
mov    %r14,%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
mov    0x8(%rbx),%rdi
jmp    1200 <main+0xb0>
lea    0xe82(%rip),%rdi
call   1040 <system@plt>
lea    0xeba(%rip),%rdi
lea    0xea4(%rip),%rbx
mov    %rbx,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xec4(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xed5(%rip),%rdi
lea    0xe71(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xe0a(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
lea    0xdc8(%rip),%rdi
lea    0xe35(%rip),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xdce(%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/bootloader.bin\00"
@.str.7 = [39 x i8] c".pioenvs/esp-wrover-kit/partitions.bin\00"
@.str.8 = [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 4096, i32 0)
%23 = call i32 @merge_flash(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 32768, i32 0)
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 1
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @merge_flash(i8* %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 65536, i32 0)
br label %33
31: ; preds = %20
%32 = call i32 @merge_flash(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, 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 %33
33: ; preds = %31, %26
%34 = call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%35 = load i32, i32* %3
ret i32 %35
}

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/bootloader.bin\00"
@.str.7 = [39 x i8] c".pioenvs/esp-wrover-kit/partitions.bin\00"
@.str.8 = [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 %19
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 4096, i32 0)
%17 = tail call i32 @merge_flash(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 32768, i32 0)
%18 = load i8*, i8** %5
br label %23
19: ; preds = %2
%20 = tail call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0))
%21 = 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 4096, i32 0)
%22 = tail call i32 @merge_flash(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, 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 %23
23: ; preds = %19, %14
%24 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), %19 ], [ %18, %14 ]
%25 = tail call i32 @merge_flash(i8* %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 65536, i32 0)
%26 = tail call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}