#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 */
typedef int /*<<< orphan*/ append_buffer;

/* Variables and functions */
int append_data_to_image(char *, unsigned long, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char append_buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  unsigned long address = 0x00112230;
  int ii;
  if (argc < 2) {
    fprintf(stderr, "usage : warp_embed_dsp [image_file]\n");
    exit(-1);
  }
  for (ii = 0; ii < sizeof(append_buffer) / 2; ii += 2) {
    char tmp = append_buffer[ii];
    append_buffer[ii] = append_buffer[ii + 1];
    append_buffer[ii + 1] = tmp;
  }
  return append_data_to_image(argv[1], address, append_buffer, 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x112230,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1182 <main+0x52>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x4,%rax
jae    11d3 <main+0xa3>
movslq -0x24(%rbp),%rax
mov    -0x18(%rbp,%rax,1),%al
mov    %al,-0x25(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x18(%rbp,%rax,1),%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x18(%rbp,%rax,1)
mov    -0x25(%rbp),%cl
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x18(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    1189 <main+0x59>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <append_data_to_image@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movabs $0x706050402030001,%rax
05 06 07
mov    %rax,(%rsp)
cmp    $0x2,%edi
jl     1159 <main+0x29>
mov    0x8(%rsi),%rdi
mov    %rsp,%rdx
mov    $0x112230,%esi
xor    %ecx,%ecx
call   1030 <append_data_to_image@plt>
pop    %rcx
ret
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@__const.main.append_buffer = [8 x i8] c"\00\01\02\03\04\05\06\07"
@stderr = global i32 0
@.str = [37 x i8] c"usage : warp_embed_dsp [image_file]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i8]
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [8 x i8]* %6 to i8*
store i64 1122864, i64* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
store i32 0, i32* %8
br label %18
18: ; preds = %40, %17
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = icmp ult i64 %20, 4
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %24
%26 = load i8, i8* %25
store i8 %26, i8* %9
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %33
store i8 %31, i8* %34
%35 = load i8, i8* %9
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %38
store i8 %35, i8* %39
br label %40
40: ; preds = %22
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 2
store i32 %42, i32* %8
br label %18
43: ; preds = %18
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = load i64, i64* %7
%48 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%49 = call i32 @append_data_to_image(i8* %46, i64 %47, i8* %48, i32 0)
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"usage : warp_embed_dsp [image_file]\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 506097522897518593, i64* %3
%5 = icmp slt i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @append_data_to_image(i8* %8, i64 1122864, i8* %4, i32 0)
ret i32 %9
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
}