#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_example.bin", "esp32flash.bin", 0x8000, 0);
  merge_flash("build/spiffs_image.img", "esp32flash.bin", 0x180000, 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    $0x8000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf0b(%rip),%rdi
lea    0xeb8(%rip),%rsi
mov    $0x180000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xeed(%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    $0x8000,%edx
xor    %ecx,%ecx
call   1040 <merge_flash@plt>
lea    0xf14(%rip),%rdi
mov    %rbx,%rsi
mov    $0x180000,%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    0xf02(%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 = [29 x i8] c"build/partitions_example.bin\00"
@.str.4 = [23 x i8] c"build/spiffs_image.img\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 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 ([29 x i8], [29 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)
%8 = call i32 @merge_flash(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 1572864, i32 0)
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = 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 = call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, 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 = [29 x i8] c"build/partitions_example.bin\00"
@.str.4 = [23 x i8] c"build/spiffs_image.img\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 ([29 x i8], [29 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 = tail call i32 @merge_flash(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 1572864, i32 0)
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @merge_flash(i8* %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 65536, i32 0)
%10 = tail call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}