#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
unsigned long fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, unsigned long,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ int2le(unsigned long, unsigned char *);
unsigned long le2int(unsigned char *);
int /*<<< orphan*/ *openinfile(char *);
int /*<<< orphan*/ *openoutfile(char *);
int /*<<< orphan*/ stderr;
int gigabeat_code(char *infile, char *outfile) {
  FILE *in, *out;
  unsigned long size = 0;
  unsigned long bytes_read;
  unsigned char buf[4];
  unsigned long data;
  unsigned long key = 0x19751217;
  in = openinfile(infile);
  out = openoutfile(outfile);
  while (!feof(in)) {
    bytes_read = fread(buf, 1, 4, in);
    data = le2int(buf);
    data = data ^ key;
    key = key + (key << 1);
    key = key + 0x19751217;
    size += bytes_read;
    int2le(data, buf);
    fwrite(buf, 1, bytes_read, out);
  }
  fprintf(stderr, "File processed successfully\n");
  fclose(in);
  fclose(out);
  return (0);
}


x86 assembly (clang, -O0):
<gigabeat_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x19751217,-0x48(%rbp)
19
mov    -0x8(%rbp),%rdi
call   1060 <openinfile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <openoutfile@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e8 <gigabeat_code+0x58>
jmp    1271 <gigabeat_code+0xe1>
lea    -0x34(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
lea    -0x34(%rbp),%rdi
call   1080 <le2int@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
xor    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x48(%rbp),%rcx
shl    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x19751217,%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   10a0 <int2le@plt>
lea    -0x34(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
jmp    11ca <gigabeat_code+0x3a>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gigabeat_code>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
call   1060 <openinfile@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1090 <openoutfile@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1228 <gigabeat_code+0x98>
mov    $0x19751217,%ebx
lea    0xc(%rsp),%r12
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   1080 <le2int@plt>
xor    %rbx,%rax
lea    (%rbx,%rbx,2),%rbx
add    $0x19751217,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   10a0 <int2le@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11d0 <gigabeat_code+0x40>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"File processed successfully\0A\00"
define i32 @gigabeat_code(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca [4 x i8]
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %7
store i64 427102743, i64* %11
%12 = load i8*, i8** %3
%13 = call i32* @openinfile(i8* %12)
store i32* %13, i32** %5
%14 = load i8*, i8** %4
%15 = call i32* @openoutfile(i8* %14)
store i32* %15, i32** %6
br label %16
16: ; preds = %21, %2
%17 = load i32*, i32** %5
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %46
21: ; preds = %16
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%23 = load i32*, i32** %5
%24 = call i64 @fread(i8* %22, i32 1, i32 4, i32* %23)
store i64 %24, i64* %8
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%26 = call i64 @le2int(i8* %25)
store i64 %26, i64* %10
%27 = load i64, i64* %10
%28 = load i64, i64* %11
%29 = xor i64 %27, %28
store i64 %29, i64* %10
%30 = load i64, i64* %11
%31 = load i64, i64* %11
%32 = shl i64 %31, 1
%33 = add i64 %30, %32
store i64 %33, i64* %11
%34 = load i64, i64* %11
%35 = add i64 %34, 427102743
store i64 %35, i64* %11
%36 = load i64, i64* %8
%37 = load i64, i64* %7
%38 = add i64 %37, %36
store i64 %38, i64* %7
%39 = load i64, i64* %10
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%41 = call i32 @int2le(i64 %39, i8* %40)
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%43 = load i64, i64* %8
%44 = load i32*, i32** %6
%45 = call i32 @fwrite(i8* %42, i32 1, i64 %43, i32* %44)
br label %16
46: ; preds = %16
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%49 = load i32*, i32** %5
%50 = call i32 @fclose(i32* %49)
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"File processed successfully\0A\00"
define i32 @gigabeat_code(i8* %0, i8* %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @openinfile(i8* %0)
%6 = tail call i32* @openoutfile(i8* %1)
%7 = call i32 @feof(i32* %5)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %2, %9
%10 = phi i64 [ %15, %9 ], [ 427102743, %2 ]
%11 = call i64 @fread(i8* %4, i32 1, i32 4, i32* %5)
%12 = call i64 @le2int(i8* %4)
%13 = xor i64 %12, %10
%14 = mul i64 %10, 3
%15 = add i64 %14, 427102743
%16 = call i32 @int2le(i64 %13, i8* %4)
%17 = call i32 @fwrite(i8* %4, i32 1, i64 %11, i32* %6)
%18 = call i32 @feof(i32* %5)
%19 = icmp eq i32 %18, 0
br i1 %19, label %9, label %20
20: ; preds = %9, %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @fclose(i32* %5)
%24 = call i32 @fclose(i32* %6)
ret i32 0
}