#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned int *, int, int, int /*<<< orphan*/ *);
unsigned int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
unsigned int strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc != 5)
    return -1;
  srand(time(NULL));
  FILE *pf = fopen(argv[1], "rb+");
  if (!pf)
    return -1;
  FILE *out = fopen(argv[2], "wb");
  unsigned int base;
  if (argv[3][0] == '0' && (argv[3][1] == 'x' || argv[3][1] == 'X'))
    base = strtol(argv[3] + 2, NULL, 16);
  else
    base = atoi(argv[3]);
  unsigned int seed;
  if (argv[4][0] == '0' && (argv[4][1] == 'x' || argv[4][1] == 'X'))
    seed = strtol(argv[4] + 2, NULL, 16);
  else
    seed = atoi(argv[4]);
  printf("Base : %08X\nSeed : %08X\n", base, seed);
  while (!feof(pf)) {
    unsigned int cur = ftell(pf);
    unsigned int word;
    fread(&word, 1, 4, pf);
    word ^= base;
    base += seed;
    fwrite(&word, 1, 4, out);
  }
  fclose(pf);
  return 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)
cmpl   $0x5,-0x8(%rbp)
je     11dc <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a4 <main+0x1f4>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe05(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121b <main+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a4 <main+0x1f4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdda(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1293 <main+0xe3>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     1271 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    1293 <main+0xe3>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
add    $0x2,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1090 <strtol@plt>
mov    %eax,-0x24(%rbp)
jmp    12a3 <main+0xf3>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1303 <main+0x153>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     12e1 <main+0x131>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    1303 <main+0x153>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
add    $0x2,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1090 <strtol@plt>
mov    %eax,-0x28(%rbp)
jmp    1313 <main+0x163>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xce7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1343 <main+0x193>
jmp    1394 <main+0x1e4>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    -0x24(%rbp),%eax
xor    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10d0 <fwrite@plt>
jmp    1325 <main+0x175>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebp
cmp    $0x5,%edi
jne    12df <main+0x12f>
mov    %rsi,%r15
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    0x8(%r15),%rdi
lea    0xe1a(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12df <main+0x12f>
mov    %rax,%rbx
mov    0x10(%r15),%rdi
lea    0xe02(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    0x18(%r15),%rdi
cmpb   $0x30,(%rdi)
jne    122e <main+0x7e>
mov    0x1(%rdi),%al
or     $0x20,%al
cmp    $0x78,%al
jne    122e <main+0x7e>
add    $0x2,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <strtol@plt>
jmp    1233 <main+0x83>
call   10c0 <atoi@plt>
mov    %eax,%ebp
mov    0x20(%r15),%rdi
cmpb   $0x30,(%rdi)
jne    1259 <main+0xa9>
mov    0x1(%rdi),%al
or     $0x20,%al
cmp    $0x78,%al
jne    1259 <main+0xa9>
add    $0x2,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <strtol@plt>
jmp    125e <main+0xae>
call   10c0 <atoi@plt>
mov    %eax,%r15d
lea    0xd9f(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    12d5 <main+0x125>
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %ebp,0xc(%rsp)
add    %r15d,%ebp
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1290 <main+0xe0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"rb+\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [25 x i8] c"Base : %08X\0ASeed : %08X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 5
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %124
15: ; preds = %2
%16 = call i32 @time(i32* null)
%17 = call i32 @srand(i32 %16)
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %25, label %24
24: ; preds = %15
store i32 -1, i32* %3
br label %124
25: ; preds = %15
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 48
br i1 %36, label %37, label %59
37: ; preds = %25
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 3
%40 = load i8*, i8** %39
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 120
br i1 %44, label %53, label %45
45: ; preds = %37
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 88
br i1 %52, label %53, label %59
53: ; preds = %45, %37
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 3
%56 = load i8*, i8** %55
%57 = getelementptr inbounds i8, i8* %56, i64 2
%58 = call i32 @strtol(i8* %57, i32* null, i32 16)
store i32 %58, i32* %8
br label %64
59: ; preds = %45, %25
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 3
%62 = load i8*, i8** %61
%63 = call i32 @atoi(i8* %62)
store i32 %63, i32* %8
br label %64
64: ; preds = %59, %53
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 4
%67 = load i8*, i8** %66
%68 = getelementptr inbounds i8, i8* %67, i64 0
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 48
br i1 %71, label %72, label %94
72: ; preds = %64
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 4
%75 = load i8*, i8** %74
%76 = getelementptr inbounds i8, i8* %75, i64 1
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = icmp eq i32 %78, 120
br i1 %79, label %88, label %80
80: ; preds = %72
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 4
%83 = load i8*, i8** %82
%84 = getelementptr inbounds i8, i8* %83, i64 1
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 88
br i1 %87, label %88, label %94
88: ; preds = %80, %72
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 4
%91 = load i8*, i8** %90
%92 = getelementptr inbounds i8, i8* %91, i64 2
%93 = call i32 @strtol(i8* %92, i32* null, i32 16)
store i32 %93, i32* %9
br label %99
94: ; preds = %80, %64
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 4
%97 = load i8*, i8** %96
%98 = call i32 @atoi(i8* %97)
store i32 %98, i32* %9
br label %99
99: ; preds = %94, %88
%100 = load i32, i32* %8
%101 = load i32, i32* %9
%102 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %100, i32 %101)
br label %103
103: ; preds = %108, %99
%104 = load i32*, i32** %6
%105 = call i32 @feof(i32* %104)
%106 = icmp ne i32 %105, 0
%107 = xor i1 %106, true
br i1 %107, label %108, label %121
108: ; preds = %103
%109 = load i32*, i32** %6
%110 = call i32 @ftell(i32* %109)
store i32 %110, i32* %10
%111 = load i32*, i32** %6
%112 = call i32 @fread(i32* %11, i32 1, i32 4, i32* %111)
%113 = load i32, i32* %8
%114 = load i32, i32* %11
%115 = xor i32 %114, %113
store i32 %115, i32* %11
%116 = load i32, i32* %9
%117 = load i32, i32* %8
%118 = add i32 %117, %116
store i32 %118, i32* %8
%119 = load i32*, i32** %7
%120 = call i32 @fwrite(i32* %11, i32 1, i32 4, i32* %119)
br label %103
121: ; preds = %103
%122 = load i32*, i32** %6
%123 = call i32 @fclose(i32* %122)
store i32 0, i32* %3
br label %124
124: ; preds = %121, %24, %14
%125 = load i32, i32* %3
ret i32 %125
}

LLVM IR (-O2):
@.str = [4 x i8] c"rb+\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [25 x i8] c"Base : %08X\0ASeed : %08X\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 5
br i1 %4, label %5, label %61
5: ; preds = %2
%6 = tail call i32 @time(i32* null)
%7 = tail call i32 @srand(i32 %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %61, label %12
12: ; preds = %5
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 48
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = load i8, i8* %21
switch i8 %22, label %26 [
i8 120, label %23
i8 88, label %23
]
23: ; preds = %20, %20
%24 = getelementptr inbounds i8, i8* %17, i64 2
%25 = tail call i32 @strtol(i8* nocapture %24, i32* null, i32 16)
br label %28
26: ; preds = %20, %12
%27 = tail call i32 @atoi(i8* %17)
br label %28
28: ; preds = %26, %23
%29 = phi i32 [ %25, %23 ], [ %27, %26 ]
%30 = getelementptr inbounds i8*, i8** %1, i64 4
%31 = load i8*, i8** %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 48
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = getelementptr inbounds i8, i8* %31, i64 1
%36 = load i8, i8* %35
switch i8 %36, label %40 [
i8 120, label %37
i8 88, label %37
]
37: ; preds = %34, %34
%38 = getelementptr inbounds i8, i8* %31, i64 2
%39 = tail call i32 @strtol(i8* nocapture %38, i32* null, i32 16)
br label %42
40: ; preds = %34, %28
%41 = tail call i32 @atoi(i8* %31)
br label %42
42: ; preds = %40, %37
%43 = phi i32 [ %39, %37 ], [ %41, %40 ]
%44 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %43)
%45 = tail call i32 @feof(i32* %10)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %59
47: ; preds = %42
%48 = bitcast i32* %3 to i8*
br label %49
49: ; preds = %47, %49
%50 = phi i32 [ %29, %47 ], [ %55, %49 ]
%51 = tail call i32 @ftell(i32* %10)
%52 = call i32 @fread(i32* %3, i32 1, i32 4, i32* %10)
%53 = load i32, i32* %3
%54 = xor i32 %53, %50
store i32 %54, i32* %3
%55 = add i32 %50, %43
%56 = call i32 @fwrite(i32* %3, i32 1, i32 4, i32* %15)
%57 = tail call i32 @feof(i32* %10)
%58 = icmp eq i32 %57, 0
br i1 %58, label %49, label %59
59: ; preds = %49, %42
%60 = tail call i32 @fclose(i32* %10)
br label %61
61: ; preds = %59, %5, %2
%62 = phi i32 [ -1, %2 ], [ 0, %59 ], [ -1, %5 ]
ret i32 %62
}