#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*/ printf(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf(" Usage %s build/app-template.bin.\n", argv[0]);
    return 0;
  }
  system("dd if=/dev/zero bs=1M count=4  | tr \"\\000\" \"\\377\" >  "
         "esp32flash.bin");
  merge_flash("build/bootloader/bootloader.bin", "esp32flash.bin", 0x1000);
  merge_flash("build/partitions.bin", "esp32flash.bin", 0x8000);
  merge_flash(argv[1], "esp32flash.bin", 0x10000);
  merge_flash("fat.bin", "esp32flash.bin", 0x300000);
  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   $0x2,-0x8(%rbp)
jge    116f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <main+0xb8>
lea    0xead(%rip),%rdi
call   1030 <system@plt>
lea    0xee5(%rip),%rdi
lea    0xecf(%rip),%rsi
mov    $0x1000,%edx
call   1050 <merge_flash@plt>
lea    0xeed(%rip),%rdi
lea    0xeb7(%rip),%rsi
mov    $0x8000,%edx
call   1050 <merge_flash@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x10000,%edx
call   1050 <merge_flash@plt>
lea    0xed1(%rip),%rdi
lea    0xe86(%rip),%rsi
mov    $0x300000,%edx
call   1050 <merge_flash@plt>
lea    0xec1(%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
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     114d <main+0x1d>
mov    (%rbx),%rsi
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
jmp    11b9 <main+0x89>
lea    0xecf(%rip),%rdi
call   1030 <system@plt>
lea    0xf07(%rip),%rdi
lea    0xef1(%rip),%r14
mov    %r14,%rsi
mov    $0x1000,%edx
call   1050 <merge_flash@plt>
lea    0xf0c(%rip),%rdi
mov    %r14,%rsi
mov    $0x8000,%edx
call   1050 <merge_flash@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
mov    $0x10000,%edx
call   1050 <merge_flash@plt>
lea    0xefc(%rip),%rdi
mov    %r14,%rsi
mov    $0x300000,%edx
call   1050 <merge_flash@plt>
lea    0xef0(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c" Usage %s build/app-template.bin.\0A\00"
@.str.1 = [68 x i8] c"dd if=/dev/zero bs=1M count=4 | tr \22\\000\22 \22\\377\22 > esp32flash.bin\00"
@.str.2 = [32 x i8] c"build/bootloader/bootloader.bin\00"
@.str.3 = [15 x i8] c"esp32flash.bin\00"
@.str.4 = [21 x i8] c"build/partitions.bin\00"
@.str.5 = [8 x i8] c"fat.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 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 slt i32 %6, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 0, i32* %3
br label %23
13: ; preds = %2
%14 = call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%15 = 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)
%16 = call i32 @merge_flash(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 32768)
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @merge_flash(i8* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 65536)
%21 = call i32 @merge_flash(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 3145728)
%22 = call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %23
23: ; preds = %13, %8
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [35 x i8] c" Usage %s build/app-template.bin.\0A\00"
@.str.1 = [68 x i8] c"dd if=/dev/zero bs=1M count=4 | tr \22\\000\22 \22\\377\22 > esp32flash.bin\00"
@.str.2 = [32 x i8] c"build/bootloader/bootloader.bin\00"
@.str.3 = [15 x i8] c"esp32flash.bin\00"
@.str.4 = [21 x i8] c"build/partitions.bin\00"
@.str.5 = [8 x i8] c"fat.bin\00"
@.str.6 = [31 x i8] c"cp esp32flash.bin ~/qemu_esp32\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %16
7: ; preds = %2
%8 = tail call i32 @system(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%9 = 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)
%10 = tail call i32 @merge_flash(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 32768)
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @merge_flash(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 65536)
%14 = tail call i32 @merge_flash(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 3145728)
%15 = tail call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %16
16: ; preds = %7, %4
ret i32 0
}