#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("components/arduino/tools/partitions/boot_app0.bin",
              "esp32flash.bin", 0xe000, 0);
  merge_flash("build/phy_init_data.bin", "esp32flash.bin", 0xf000, 0);
  merge_flash("build/default.bin", "esp32flash.bin", 0x8000, 0);
  merge_flash(argv[1], "esp32flash.bin", 0x10000, 0);
  system("cp esp32flash.bin ~/qemu_esp32");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <system@plt>
lea    0xf02(%rip),%rdi
lea    0xeec(%rip),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf08(%rip),%rdi
lea    0xed2(%rip),%rsi
mov    $0xe000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf20(%rip),%rdi
lea    0xeb8(%rip),%rsi
mov    $0xf000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf1e(%rip),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe83(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xefb(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xed2(%rip),%rdi
call   1030 <system@plt>
lea    0xf0a(%rip),%rdi
lea    0xef4(%rip),%rbx
mov    %rbx,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf0d(%rip),%rdi
mov    %rbx,%rsi
mov    $0xe000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf29(%rip),%rdi
mov    %rbx,%rsi
mov    $0xf000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf2b(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
mov    0x8(%r14),%rdi
mov    %rbx,%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf14(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 = [50 x i8] c"components/arduino/tools/partitions/boot_app0.bin\00"
@.str.4 = [24 x i8] c"build/phy_init_data.bin\00"
@.str.5 = [18 x i8] c"build/default.bin\00"
@.str.6 = [31 x i8] c"cp esp32flash.bin ~/qemu_esp32\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
store i32 %0, i32* %3
store i8** %1, i8*** %4
%5 = call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%6 = 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)
%7 = call i32 @merge_flash(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 57344, i32 0)
%8 = call i32 @merge_flash(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 61440, i32 0)
%9 = call i32 @merge_flash(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 32768, i32 0)
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @merge_flash(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 65536, i32 0)
%14 = call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

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 = [50 x i8] c"components/arduino/tools/partitions/boot_app0.bin\00"
@.str.4 = [24 x i8] c"build/phy_init_data.bin\00"
@.str.5 = [18 x i8] c"build/default.bin\00"
@.str.6 = [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 ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 57344, i32 0)
%6 = tail call i32 @merge_flash(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 61440, i32 0)
%7 = tail call i32 @merge_flash(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 32768, i32 0)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @merge_flash(i8* %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 65536, i32 0)
%11 = tail call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}