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

/* Variables and functions */
scalar_t__ read(int /*<<< orphan*/, char *, int);
char strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int n = 0;
  int x = 0;
  char buf[4], key[4];
  key[0] = strtol(argv[1], NULL, 16);
  key[1] = strtol(argv[2], NULL, 16);
  key[2] = strtol(argv[3], NULL, 16);
  key[3] = strtol(argv[4], NULL, 16);
  while (read(0, buf, 4)) {
    for (x = 0; x < 4; x++)
      buf[x] = buf[x] ^ key[x] ^ (n + x);
    write(1, buf, 4);
    n += 4;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %al,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %al,-0x1f(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %al,-0x1e(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %al,-0x1d(%rbp)
lea    -0x1c(%rbp),%rsi
xor    %edi,%edi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
je     1238 <main+0x108>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1217 <main+0xe7>
movslq -0x18(%rbp),%rax
movsbl -0x1c(%rbp,%rax,1),%eax
movslq -0x18(%rbp),%rcx
movsbl -0x20(%rbp,%rcx,1),%ecx
xor    %ecx,%eax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
xor    %ecx,%eax
mov    %al,%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x1c(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d9 <main+0xa9>
lea    -0x1c(%rbp),%rsi
mov    $0x1,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <main+0x88>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %eax,%r12d
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %eax,%r15d
mov    0x20(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %eax,%r13d
lea    0x4(%rsp),%rsi
xor    %edi,%edi
mov    $0x4,%edx
call   1040 <read@plt>
test   %rax,%rax
je     1211 <main+0xe1>
mov    $0x3,%bl
lea    0x4(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
lea    -0x3(%rbx),%eax
xor    0x4(%rsp),%al
xor    %r12b,%al
mov    %al,0x4(%rsp)
lea    -0x2(%rbx),%eax
xor    0x5(%rsp),%al
xor    %r14b,%al
mov    %al,0x5(%rsp)
lea    -0x1(%rbx),%eax
xor    0x6(%rsp),%al
xor    %r15b,%al
mov    %al,0x6(%rsp)
movzbl 0x7(%rsp),%eax
xor    %bl,%al
xor    %r13b,%al
mov    %al,0x7(%rsp)
mov    $0x1,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
add    $0x4,%bl
test   %rax,%rax
jne    11b0 <main+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i8]
%9 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call signext i8 @strtol(i8* %12, i32* null, i32 16)
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
store i8 %13, i8* %14
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call signext i8 @strtol(i8* %17, i32* null, i32 16)
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
store i8 %18, i8* %19
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call signext i8 @strtol(i8* %22, i32* null, i32 16)
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
store i8 %23, i8* %24
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 4
%27 = load i8*, i8** %26
%28 = call signext i8 @strtol(i8* %27, i32* null, i32 16)
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
store i8 %28, i8* %29
br label %30
30: ; preds = %61, %2
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%32 = call i64 @read(i32 0, i8* %31, i32 4)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %66
34: ; preds = %30
store i32 0, i32* %7
br label %35
35: ; preds = %58, %34
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 4
br i1 %37, label %38, label %61
38: ; preds = %35
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = xor i32 %43, %48
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = add nsw i32 %50, %51
%53 = xor i32 %49, %52
%54 = trunc i32 %53 to i8
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 %56
store i8 %54, i8* %57
br label %58
58: ; preds = %38
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %35
61: ; preds = %35
%62 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%63 = call i32 @write(i32 1, i8* %62, i32 4)
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 4
store i32 %65, i32* %6
br label %30
66: ; preds = %30
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call signext i8 @strtol(i8* nocapture %6, i32* null, i32 16)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call signext i8 @strtol(i8* nocapture %9, i32* null, i32 16)
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call signext i8 @strtol(i8* nocapture %12, i32* null, i32 16)
%14 = getelementptr inbounds i8*, i8** %1, i64 4
%15 = load i8*, i8** %14
%16 = tail call signext i8 @strtol(i8* nocapture %15, i32* null, i32 16)
%17 = call i64 @read(i32 0, i8* %4, i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %48, label %19
19: ; preds = %2
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
br label %23
23: ; preds = %19, %23
%24 = phi i32 [ %45, %23 ], [ 0, %19 ]
%25 = load i8, i8* %4
%26 = trunc i32 %24 to i8
%27 = xor i8 %25, %26
%28 = xor i8 %27, %7
store i8 %28, i8* %4
%29 = load i8, i8* %20
%30 = trunc i32 %24 to i8
%31 = or i8 %30, 1
%32 = xor i8 %29, %31
%33 = xor i8 %32, %10
store i8 %33, i8* %20
%34 = load i8, i8* %21
%35 = trunc i32 %24 to i8
%36 = or i8 %35, 2
%37 = xor i8 %34, %36
%38 = xor i8 %37, %13
store i8 %38, i8* %21
%39 = load i8, i8* %22
%40 = trunc i32 %24 to i8
%41 = or i8 %40, 3
%42 = xor i8 %39, %41
%43 = xor i8 %42, %16
store i8 %43, i8* %22
%44 = call i32 @write(i32 1, i8* %4, i32 4)
%45 = add nuw nsw i32 %24, 4
%46 = call i64 @read(i32 0, i8* %4, i32 4)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %23
48: ; preds = %23, %2
ret i32 0
}