#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 */
unsigned char *data_from_file_raw(char *, int *);
int /*<<< orphan*/ data_to_file_raw(unsigned char *, int, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ xor_encode(unsigned char *, int, unsigned char *, int,
                              unsigned char *);
int main(int argc, char **argv) {
  int payload_size;
  int key_length;
  printf("Starting XOR encoder...\n");
  printf("Reading payload from file %s, expecting raw format.\n", argv[1]);
  unsigned char *payload = data_from_file_raw(argv[1], &payload_size);
  printf("payload size in bytes is %d\n", payload_size);
  printf("Reading key from file %s, expecting raw format.\n", argv[3]);
  unsigned char *key = data_from_file_raw(argv[3], &key_length);
  printf("Key length in bytes is %d\n", key_length);
  unsigned char *ciphertext = (unsigned char *)malloc(payload_size);
  printf("Applying XOR algorithm\n");
  xor_encode(payload, payload_size, key, key_length, ciphertext);
  printf("Writing payload to file %s\n", argv[2]);
  data_to_file_raw(ciphertext, payload_size, argv[2]);
  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)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <data_from_file_raw@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <data_from_file_raw@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%esi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x30(%rbp),%r8
call   1060 <xor_encode@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
call   1040 <data_to_file_raw@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xf48(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rsi
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1080 <data_from_file_raw@plt>
mov    %rax,%r14
mov    (%rsp),%esi
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%rsi
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%rdi
lea    0x4(%rsp),%rsi
call   1080 <data_from_file_raw@plt>
mov    %rax,%r15
mov    0x4(%rsp),%esi
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%ecx
mov    %r14,%rdi
mov    %r15,%rdx
mov    %r12,%r8
call   1070 <xor_encode@plt>
mov    0x10(%rbx),%rsi
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%esi
mov    0x10(%rbx),%rdx
mov    %r12,%rdi
call   1050 <data_to_file_raw@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Starting XOR encoder...\0A\00"
@.str.1 = [53 x i8] c"Reading payload from file %s, expecting raw format.\0A\00"
@.str.2 = [29 x i8] c"payload size in bytes is %d\0A\00"
@.str.3 = [49 x i8] c"Reading key from file %s, expecting raw format.\0A\00"
@.str.4 = [27 x i8] c"Key length in bytes is %d\0A\00"
@.str.5 = [24 x i8] c"Applying XOR algorithm\0A\00"
@.str.6 = [28 x i8] c"Writing payload to file %s\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 i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i8* @data_from_file_raw(i8* %18, i32* %6)
store i8* %19, i8** %8
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i8* @data_from_file_raw(i8* %28, i32* %7)
store i8* %29, i8** %9
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %6
%33 = call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %10
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%36 = load i8*, i8** %8
%37 = load i32, i32* %6
%38 = load i8*, i8** %9
%39 = load i32, i32* %7
%40 = load i8*, i8** %10
%41 = call i32 @xor_encode(i8* %36, i32 %37, i8* %38, i32 %39, i8* %40)
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %44)
%46 = load i8*, i8** %10
%47 = load i32, i32* %6
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @data_to_file_raw(i8* %46, i32 %47, i8* %50)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [53 x i8] c"Reading payload from file %s, expecting raw format.\0A\00"
@.str.2 = [29 x i8] c"payload size in bytes is %d\0A\00"
@.str.3 = [49 x i8] c"Reading key from file %s, expecting raw format.\0A\00"
@.str.4 = [27 x i8] c"Key length in bytes is %d\0A\00"
@.str.6 = [28 x i8] c"Writing payload to file %s\0A\00"
@str = [24 x i8] c"Starting XOR encoder...\00"
@str.7 = [23 x i8] c"Applying XOR algorithm\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %8
%12 = call i8* @data_from_file_raw(i8* %11, i32* %3)
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %15
%19 = call i8* @data_from_file_raw(i8* %18, i32* %4)
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %3
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 @xor_encode(i8* %12, i32 %26, i8* %19, i32 %27, i8* %24)
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %3
%33 = load i8*, i8** %29
%34 = call i32 @data_to_file_raw(i8* %24, i32 %32, i8* %33)
ret i32 0
}