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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
void write_asm_data(FILE *in, FILE *out) {
  int i, cnt, pos = 0;
  unsigned int cksum = 0, val;
  unsigned char *lp;
  unsigned char buf[0x1000];
  size_t len;
  fputs("\t.data\n\t.globl input_data\ninput_data:\n", out);
  while ((len = fread(buf, 1, sizeof(buf), in)) > 0) {
    cnt = 0;
    lp = buf;
    while (len & 3)
      buf[len++] = '\0';
    for (i = 0; i < len; i += 4) {
      if (cnt == 0)
        fputs("\t.long\t", out);
      fprintf(out, "0x%02X%02X%02X%02X", lp[0], lp[1], lp[2], lp[3]);
      val = *(unsigned long *)lp;
      cksum ^= val;
      lp += 4;
      if (++cnt == 4) {
        cnt = 0;
        fprintf(out, " # %x \n", pos + i - 12);
      } else {
        fputs(",", out);
      }
    }
    if (cnt)
      fputs("0\n", out);
    pos += len;
  }
  fprintf(out, "\t.globl input_len\ninput_len:\t.long\t0x%x\n", pos);
  fprintf(stderr, "cksum = %x\n", cksum);
}


x86 assembly (clang, -O0):
<write_asm_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea4(%rip),%rdi
call   1040 <fputs@plt>
lea    -0x1030(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1038(%rbp)
cmp    $0x0,%rax
jbe    12e5 <write_asm_data+0x1b5>
movl   $0x0,-0x18(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1038(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
je     11d5 <write_asm_data+0xa5>
mov    -0x1038(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x1038(%rbp)
movb   $0x0,-0x1030(%rbp,%rax,1)
jmp    119e <write_asm_data+0x6e>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x1038(%rbp),%rax
jae    12b5 <write_asm_data+0x185>
cmpl   $0x0,-0x18(%rbp)
jne    1207 <write_asm_data+0xd7>
mov    -0x10(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rax
movzbl (%rax),%edx
mov    -0x30(%rbp),%rax
movzbl 0x1(%rax),%ecx
mov    -0x30(%rbp),%rax
movzbl 0x2(%rax),%r8d
mov    -0x30(%rbp),%rax
movzbl 0x3(%rax),%r9d
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
xor    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x4,%eax
jne    1292 <write_asm_data+0x162>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
add    -0x14(%rbp),%edx
sub    $0xc,%edx
lea    0xdbc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12a2 <write_asm_data+0x172>
mov    -0x10(%rbp),%rsi
lea    0xdad(%rip),%rdi
call   1040 <fputs@plt>
jmp    12a7 <write_asm_data+0x177>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    11dc <write_asm_data+0xac>
cmpl   $0x0,-0x18(%rbp)
je     12cf <write_asm_data+0x19f>
mov    -0x10(%rbp),%rsi
lea    0xd82(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x1038(%rbp),%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
jmp    1161 <write_asm_data+0x31>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%edx
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_asm_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe92(%rip),%rdi
mov    $0x26,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbp,0x8(%rsp)
mov    %rbp,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     12e8 <write_asm_data+0x198>
mov    %rax,%r14
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    11dc <write_asm_data+0x8c>
nop
mov    (%rsp),%r15
add    %r14d,%r15d
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    0x8(%rsp),%rcx
call   1030 <fread@plt>
mov    %rax,%r14
test   %rax,%rax
je     12ed <write_asm_data+0x19d>
test   $0x3,%r14b
je     120f <write_asm_data+0xbf>
lea    (%rsp,%r14,1),%rdi
add    $0x10,%rdi
mov    %r14d,%eax
and    $0x3,%eax
mov    $0x4,%edx
sub    %rax,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rax
or     $0xfffffffffffffffc,%rax
sub    %rax,%r14
je     12e0 <write_asm_data+0x190>
mov    %r15,(%rsp)
add    $0xfffffff4,%r15d
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    126e <write_asm_data+0x11e>
nop
movzbl 0x10(%rsp,%r12,1),%edx
movzbl 0x11(%rsp,%r12,1),%ecx
movzbl 0x12(%rsp,%r12,1),%r8d
movzbl 0x13(%rsp,%r12,1),%r9d
mov    %rbx,%rdi
lea    0xded(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    0x10(%rsp,%r12,1),%ebp
add    $0x1,%r13d
cmp    $0x4,%r13d
je     1290 <write_asm_data+0x140>
mov    $0x2c,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x4,%r12
cmp    %r12,%r14
jbe    12b0 <write_asm_data+0x160>
test   %r13d,%r13d
jne    1220 <write_asm_data+0xd0>
mov    $0x7,%esi
mov    $0x1,%edx
lea    0xda3(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
jmp    1220 <write_asm_data+0xd0>
xchg   %ax,%ax
lea    (%r15,%r12,1),%edx
xor    %r13d,%r13d
mov    %rbx,%rdi
lea    0xda1(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1265 <write_asm_data+0x115>
nopw   0x0(%rax,%rax,1)
test   %r13d,%r13d
je     11b0 <write_asm_data+0x60>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xd80(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
jmp    11b0 <write_asm_data+0x60>
nopw   0x0(%rax,%rax,1)
xor    %r14d,%r14d
jmp    11b4 <write_asm_data+0x64>
xor    %r15d,%r15d
xor    %ebp,%ebp
lea    0xd59(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2cd8(%rip),%rax
mov    (%rax),%rdi
lea    0xd64(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"\09.data\0A\09.globl input_data\0Ainput_data:\0A\00"
@.str.1 = [8 x i8] c"\09.long\09\00"
@.str.2 = [19 x i8] c"0x%02X%02X%02X%02X\00"
@.str.3 = [8 x i8] c" # %x \0A\00"
@.str.4 = [2 x i8] c",\00"
@.str.5 = [3 x i8] c"0\0A\00"
@.str.6 = [41 x i8] c"\09.globl input_len\0Ainput_len:\09.long\090x%x\0A\00"
@stderr = global i32* null
@.str.7 = [12 x i8] c"cksum = %x\0A\00"
define void @write_asm_data(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [4096 x i8]
%12 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %7
store i32 0, i32* %8
%13 = load i32*, i32** %4
%14 = call i32 @fputs(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32* %13)
br label %15
15: ; preds = %93, %2
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i64 @fread(i8* %16, i32 1, i32 4096, i32* %17)
store i64 %18, i64* %12
%19 = icmp ugt i64 %18, 0
br i1 %19, label %20, label %99
20: ; preds = %15
store i32 0, i32* %6
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
store i8* %21, i8** %10
br label %22
22: ; preds = %26, %20
%23 = load i64, i64* %12
%24 = and i64 %23, 3
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i64, i64* %12
%28 = add i64 %27, 1
store i64 %28, i64* %12
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 %27
store i8 0, i8* %29
br label %22
30: ; preds = %22
store i32 0, i32* %5
br label %31
31: ; preds = %84, %30
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = load i64, i64* %12
%35 = icmp ult i64 %33, %34
br i1 %35, label %36, label %87
36: ; preds = %31
%37 = load i32, i32* %6
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32*, i32** %4
%41 = call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %40)
br label %42
42: ; preds = %39, %36
%43 = load i32*, i32** %4
%44 = load i8*, i8** %10
%45 = getelementptr inbounds i8, i8* %44, i64 0
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = load i8*, i8** %10
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = load i8*, i8** %10
%53 = getelementptr inbounds i8, i8* %52, i64 2
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = load i8*, i8** %10
%57 = getelementptr inbounds i8, i8* %56, i64 3
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 %51, i32 %55, i32 %59)
%61 = load i8*, i8** %10
%62 = bitcast i8* %61 to i64*
%63 = load i64, i64* %62
%64 = trunc i64 %63 to i32
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = load i32, i32* %8
%67 = xor i32 %66, %65
store i32 %67, i32* %8
%68 = load i8*, i8** %10
%69 = getelementptr inbounds i8, i8* %68, i64 4
store i8* %69, i8** %10
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
%72 = icmp eq i32 %71, 4
br i1 %72, label %73, label %80
73: ; preds = %42
store i32 0, i32* %6
%74 = load i32*, i32** %4
%75 = load i32, i32* %7
%76 = load i32, i32* %5
%77 = add nsw i32 %75, %76
%78 = sub nsw i32 %77, 12
%79 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %74, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %78)
br label %83
80: ; preds = %42
%81 = load i32*, i32** %4
%82 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* %81)
br label %83
83: ; preds = %80, %73
br label %84
84: ; preds = %83
%85 = load i32, i32* %5
%86 = add nsw i32 %85, 4
store i32 %86, i32* %5
br label %31
87: ; preds = %31
%88 = load i32, i32* %6
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %87
%91 = load i32*, i32** %4
%92 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %91)
br label %93
93: ; preds = %90, %87
%94 = load i64, i64* %12
%95 = load i32, i32* %7
%96 = sext i32 %95 to i64
%97 = add i64 %96, %94
%98 = trunc i64 %97 to i32
store i32 %98, i32* %7
br label %15
99: ; preds = %15
%100 = load i32*, i32** %4
%101 = load i32, i32* %7
%102 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %100, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %101)
%103 = load i32*, i32** @stderr
%104 = load i32, i32* %8
%105 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %103, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %104)
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"\09.data\0A\09.globl input_data\0Ainput_data:\0A\00"
@.str.1 = [8 x i8] c"\09.long\09\00"
@.str.2 = [19 x i8] c"0x%02X%02X%02X%02X\00"
@.str.3 = [8 x i8] c" # %x \0A\00"
@.str.5 = [3 x i8] c"0\0A\00"
@.str.6 = [41 x i8] c"\09.globl input_len\0Ainput_len:\09.long\090x%x\0A\00"
@stderr = global i32* null
@.str.7 = [12 x i8] c"cksum = %x\0A\00"
define void @write_asm_data(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 38, i64 1, i32* %1)
%6 = call i64 @fread(i8* %4, i32 1, i32 4096, i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %73, label %8
8: ; preds = %2, %66
%9 = phi i64 [ %71, %66 ], [ %6, %2 ]
%10 = phi i32 [ %67, %66 ], [ 0, %2 ]
%11 = phi i32 [ %70, %66 ], [ 0, %2 ]
%12 = and i64 %9, 3
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %8
%15 = getelementptr [4096 x i8], [4096 x i8]* %3, i64 0, i64 %9
%16 = and i64 %9, 3
%17 = sub nuw nsw i64 4, %16
%18 = or i64 %9, -4
%19 = sub i64 %9, %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %66, label %21
21: ; preds = %8, %14
%22 = phi i64 [ %19, %14 ], [ %9, %8 ]
%23 = add i32 %11, -12
br label %24
24: ; preds = %21, %58
%25 = phi i64 [ 0, %21 ], [ %60, %58 ]
%26 = phi i8* [ %4, %21 ], [ %49, %58 ]
%27 = phi i32 [ %10, %21 ], [ %48, %58 ]
%28 = phi i32 [ 0, %21 ], [ %59, %58 ]
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = tail call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 7, i64 1, i32* %1)
br label %32
32: ; preds = %30, %24
%33 = load i8, i8* %26
%34 = zext i8 %33 to i32
%35 = getelementptr inbounds i8, i8* %26, i64 1
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = getelementptr inbounds i8, i8* %26, i64 2
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = getelementptr inbounds i8, i8* %26, i64 3
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %37, i32 %40, i32 %43)
%45 = bitcast i8* %26 to i64*
%46 = load i64, i64* %45
%47 = trunc i64 %46 to i32
%48 = xor i32 %27, %47
%49 = getelementptr inbounds i8, i8* %26, i64 4
%50 = add nsw i32 %28, 1
%51 = icmp eq i32 %50, 4
br i1 %51, label %52, label %56
52: ; preds = %32
%53 = trunc i64 %25 to i32
%54 = add i32 %23, %53
%55 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %54)
br label %58
56: ; preds = %32
%57 = tail call i32 @fputc(i32 44, i32* %1)
br label %58
58: ; preds = %52, %56
%59 = phi i32 [ 0, %52 ], [ %50, %56 ]
%60 = add nuw i64 %25, 4
%61 = icmp ugt i64 %22, %60
br i1 %61, label %24, label %62
62: ; preds = %58
%63 = icmp eq i32 %59, 0
br i1 %63, label %66, label %64
64: ; preds = %62
%65 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %66
66: ; preds = %14, %64, %62
%67 = phi i32 [ %48, %64 ], [ %48, %62 ], [ %10, %14 ]
%68 = phi i64 [ %22, %64 ], [ %22, %62 ], [ 0, %14 ]
%69 = trunc i64 %68 to i32
%70 = add i32 %11, %69
%71 = call i64 @fread(i8* %4, i32 1, i32 4096, i32* %0)
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %8
73: ; preds = %66, %2
%74 = phi i32 [ 0, %2 ], [ %70, %66 ]
%75 = phi i32 [ 0, %2 ], [ %67, %66 ]
%76 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %74)
%77 = load i32*, i32** @stderr
%78 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %75)
ret void
}