#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_jp2file(char *);
char *read_xmlfile(char *, long *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fp;
  char *xmldata, type[] = "xml ";
  long fsize, boxsize;
  if (argc < 3) {
    fprintf(stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0]);
    return -1;
  }
  fp = open_jp2file(argv[1]);
  if (!fp)
    return -1;
  xmldata = read_xmlfile(argv[2], &fsize);
  if (fsize < 0)
    return -1;
  boxsize = fsize + 8;
  fputc((boxsize >> 24) & 0xff, fp);
  fputc((boxsize >> 16) & 0xff, fp);
  fputc((boxsize >> 8) & 0xff, fp);
  fputc(boxsize & 0xff, fp);
  fwrite(type, 4, 1, fp);
  fwrite(xmldata, (size_t)fsize, 1, fp);
  free(xmldata);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe74(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xe6f(%rip),%al
mov    %al,-0x21(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ca <main+0x5a>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4c(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cc <main+0x15c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <open_jp2file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f2 <main+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cc <main+0x15c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <read_xmlfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    121e <main+0xae>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cc <main+0x15c>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
sar    $0x18,%rdi
and    $0xff,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fputc@plt>
mov    -0x38(%rbp),%rdi
sar    $0x10,%rdi
and    $0xff,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fputc@plt>
mov    -0x38(%rbp),%rdi
sar    $0x8,%rdi
and    $0xff,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fputc@plt>
mov    -0x38(%rbp),%rdi
and    $0xff,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fputc@plt>
lea    -0x25(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
movb   $0x0,0xc(%rsp)
movl   $0x206c6d78,0x8(%rsp)
20
cmp    $0x2,%edi
jg     11b1 <main+0x41>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe63(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    125b <main+0xeb>
mov    0x8(%rbx),%rdi
call   1080 <open_jp2file@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     125b <main+0xeb>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0x10(%rsp),%rsi
call   1030 <read_xmlfile@plt>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
js     125b <main+0xeb>
mov    %rax,%r14
add    $0x8,%rbx
mov    %ebx,%edi
shr    $0x18,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
movzbl %bh,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
movzbl %bl,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.type = [5 x i8] c"xml \00"
@stderr = global i32 0
@.str = [35 x i8] c"USAGE: %s modifing.jp2 adding.xml\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [5 x i8]
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [5 x i8]* %8 to i8*
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %3
br label %69
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @open_jp2file(i8* %23)
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %28, label %27
27: ; preds = %20
store i32 -1, i32* %3
br label %69
28: ; preds = %20
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i8* @read_xmlfile(i8* %31, i64* %9)
store i8* %32, i8** %7
%33 = load i64, i64* %9
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %28
store i32 -1, i32* %3
br label %69
36: ; preds = %28
%37 = load i64, i64* %9
%38 = add nsw i64 %37, 8
store i64 %38, i64* %10
%39 = load i64, i64* %10
%40 = ashr i64 %39, 24
%41 = and i64 %40, 255
%42 = load i32*, i32** %6
%43 = call i32 @fputc(i64 %41, i32* %42)
%44 = load i64, i64* %10
%45 = ashr i64 %44, 16
%46 = and i64 %45, 255
%47 = load i32*, i32** %6
%48 = call i32 @fputc(i64 %46, i32* %47)
%49 = load i64, i64* %10
%50 = ashr i64 %49, 8
%51 = and i64 %50, 255
%52 = load i32*, i32** %6
%53 = call i32 @fputc(i64 %51, i32* %52)
%54 = load i64, i64* %10
%55 = and i64 %54, 255
%56 = load i32*, i32** %6
%57 = call i32 @fputc(i64 %55, i32* %56)
%58 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%59 = load i32*, i32** %6
%60 = call i32 @fwrite(i8* %58, i64 4, i32 1, i32* %59)
%61 = load i8*, i8** %7
%62 = load i64, i64* %9
%63 = load i32*, i32** %6
%64 = call i32 @fwrite(i8* %61, i64 %62, i32 1, i32* %63)
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
%67 = load i32*, i32** %6
%68 = call i32 @fclose(i32* %67)
store i32 0, i32* %3
br label %69
69: ; preds = %36, %35, %27, %14
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@__const.main.type = [5 x i8] c"xml \00"
@stderr = global i32 0
@.str = [35 x i8] c"USAGE: %s modifing.jp2 adding.xml\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i8]
%4 = alloca i64
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = bitcast i64* %4 to i8*
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %41
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @open_jp2file(i8* %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %41, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = call i8* @read_xmlfile(i8* %19, i64* %4)
%21 = load i64, i64* %4
%22 = icmp slt i64 %21, 0
br i1 %22, label %41, label %23
23: ; preds = %17
%24 = add nuw nsw i64 %21, 8
%25 = lshr i64 %24, 24
%26 = and i64 %25, 255
%27 = call i32 @fputc(i64 %26, i32* %15)
%28 = lshr i64 %24, 16
%29 = and i64 %28, 255
%30 = call i32 @fputc(i64 %29, i32* %15)
%31 = lshr i64 %24, 8
%32 = and i64 %31, 255
%33 = call i32 @fputc(i64 %32, i32* %15)
%34 = and i64 %24, 255
%35 = call i32 @fputc(i64 %34, i32* %15)
%36 = call i32 @fwrite(i8* %5, i64 4, i32 1, i32* %15)
%37 = load i64, i64* %4
%38 = call i32 @fwrite(i8* %20, i64 %37, i32 1, i32* %15)
%39 = call i32 @free(i8* %20)
%40 = call i32 @fclose(i32* %15)
br label %41
41: ; preds = %17, %12, %23, %8
%42 = phi i32 [ -1, %8 ], [ 0, %23 ], [ -1, %12 ], [ -1, %17 ]
ret i32 %42
}