#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*/ merge_flash(char *, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  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_singleapp.bin", "esp32flash.bin", 0x8000, 0);
  if (argc > 1) {
    merge_flash(argv[1], "esp32flash.bin", 0x10000, 0);
  } else {
    merge_flash("build/14_basic_webserver.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)
lea    0xec3(%rip),%rdi
call   1030 <system@plt>
lea    0xefb(%rip),%rdi
lea    0xee5(%rip),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf01(%rip),%rdi
lea    0xecb(%rip),%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11a0 <main+0x80>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xea6(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
jmp    11ba <main+0x9a>
lea    0xedc(%rip),%rdi
lea    0xe87(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xedf(%rip),%rdi
call   1030 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xed0(%rip),%rdi
call   1030 <system@plt>
lea    0xf08(%rip),%rdi
lea    0xef2(%rip),%rbx
mov    %rbx,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf0b(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
cmp    $0x2,%ebp
jl     1173 <main+0x53>
mov    0x8(%r14),%rdi
jmp    117a <main+0x5a>
lea    0xf09(%rip),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf0c(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [68 x i8] c"dd if=/dev/zero bs=1M count=4 | tr \22\\000\22 \22\\377\22 > esp32flash.bin\00"
@.str.1 = [32 x i8] c"build/bootloader/bootloader.bin\00"
@.str.2 = [15 x i8] c"esp32flash.bin\00"
@.str.3 = [31 x i8] c"build/partitions_singleapp.bin\00"
@.str.4 = [29 x i8] c"build/14_basic_webserver.bin\00"
@.str.5 = [31 x i8] c"cp esp32flash.bin ~/qemu_esp32\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 = call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @merge_flash(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 4096, i32 0)
%8 = call i32 @merge_flash(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 32768, i32 0)
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @merge_flash(i8* %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 65536, i32 0)
br label %18
16: ; preds = %2
%17 = call i32 @merge_flash(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 65536, i32 0)
br label %18
18: ; preds = %16, %11
%19 = call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [68 x i8] c"dd if=/dev/zero bs=1M count=4 | tr \22\\000\22 \22\\377\22 > esp32flash.bin\00"
@.str.1 = [32 x i8] c"build/bootloader/bootloader.bin\00"
@.str.2 = [15 x i8] c"esp32flash.bin\00"
@.str.3 = [31 x i8] c"build/partitions_singleapp.bin\00"
@.str.4 = [29 x i8] c"build/14_basic_webserver.bin\00"
@.str.5 = [31 x i8] c"cp esp32flash.bin ~/qemu_esp32\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @merge_flash(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 4096, i32 0)
%5 = tail call i32 @merge_flash(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 32768, i32 0)
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
br label %10
10: ; preds = %2, %7
%11 = phi i8* [ %9, %7 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), %2 ]
%12 = tail call i32 @merge_flash(i8* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 65536, i32 0)
%13 = tail call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}