#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("build/bootloader/bootloader.bin", "esp32flash.bin", 0x1000, 0);
  merge_flash("build/partitions_example.bin", "esp32flash.bin", 0x8000, 0);
  merge_flash("build/spiffs_image.img", "esp32flash.bin", 0x180000, 0);
  if (argc > 1) {
    merge_flash(argv[1], "esp32flash.bin", 0x10000, 0);
  } else {
    merge_flash("build/app-template.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    0xe41(%rip),%rdi
lea    0xeae(%rip),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xeaa(%rip),%rdi
lea    0xe94(%rip),%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xead(%rip),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x180000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1250 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe55(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
jmp    126a <main+0x11a>
lea    0xe80(%rip),%rdi
lea    0xe36(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xdcf(%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     11d0 <main+0x80>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe99(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1255 <main+0x105>
lea    0xec7(%rip),%rdi
call   1040 <system@plt>
lea    0xe7c(%rip),%rdi
lea    0xee9(%rip),%r14
mov    %r14,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xee2(%rip),%rdi
mov    %r14,%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xee9(%rip),%rdi
mov    %r14,%rsi
mov    $0x180000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
mov    0x8(%rbx),%rdi
jmp    122c <main+0xdc>
lea    0xe6c(%rip),%rdi
call   1040 <system@plt>
lea    0xe21(%rip),%rdi
lea    0xe8e(%rip),%rbx
mov    %rbx,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xe87(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xe8e(%rip),%rdi
mov    %rbx,%rsi
mov    $0x180000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xe8f(%rip),%rdi
lea    0xe45(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xdde(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xd9c(%rip),%rdi
lea    0xe09(%rip),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <merge_flash@plt>
lea    0xda2(%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 = [29 x i8] c"build/partitions_example.bin\00"
@.str.7 = [23 x i8] c"build/spiffs_image.img\00"
@.str.8 = [23 x i8] c"build/app-template.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 ([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)
%23 = call i32 @merge_flash(i8* getelementptr inbounds ([29 x i8], [29 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)
%24 = call i32 @merge_flash(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 1572864, i32 0)
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 1
br i1 %26, label %27, label %32
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @merge_flash(i8* %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 65536, i32 0)
br label %34
32: ; preds = %20
%33 = call i32 @merge_flash(i8* getelementptr inbounds ([23 x i8], [23 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 %34
34: ; preds = %32, %27
%35 = call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* %3
ret i32 %36
}

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 = [29 x i8] c"build/partitions_example.bin\00"
@.str.7 = [23 x i8] c"build/spiffs_image.img\00"
@.str.8 = [23 x i8] c"build/app-template.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 %20
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 ([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 = tail call i32 @merge_flash(i8* getelementptr inbounds ([29 x i8], [29 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)
%18 = tail call i32 @merge_flash(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 1572864, i32 0)
%19 = load i8*, i8** %5
br label %25
20: ; preds = %2
%21 = tail call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0))
%22 = 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)
%23 = tail call i32 @merge_flash(i8* getelementptr inbounds ([29 x i8], [29 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)
%24 = tail call i32 @merge_flash(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 1572864, i32 0)
br label %25
25: ; preds = %20, %14
%26 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), %20 ], [ %19, %14 ]
%27 = tail call i32 @merge_flash(i8* %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 65536, i32 0)
%28 = tail call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}