#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*/ key;
typedef int /*<<< orphan*/ encrypted;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
size_t calculate_size(int);
long lseek(int, long, int /*<<< orphan*/);
scalar_t__ malloc(size_t);
int open_file(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, size_t);
int /*<<< orphan*/ write(int, char *, int);
void encrypt_decrypt(char *filename) {
  long position;
  char key[] = {'n', 'w', 'W', 'Z', 'T', 'M', '5', 'J', 'S', 'z', 'a', 'L', 'D',
                '0', 'W', 't', 'Q', '8', 'd', 'G', 'w', 'I', 'n', 'O', 'l', 'H',
                'f', 'U', 'h', 'd', '7', 'z', 'Y', '2', '6', 'Z', '8', 'O', 'K',
                'N', 'F', 'M', 'l', 'k', 'J', 'O', 'n', 'C', 'r', '7', 'I', '8',
                'Q', 'K', 'u', '5', '7', '5', '2', 'H', 'y', 'V', 'P', 'g'};
  int fd = open_file(filename);
  size_t size = calculate_size(fd);
  printf("opened file with the size of %ld bytes", size);
  char *input = (char *)malloc(size * sizeof(char));
  read(fd, input, size);
  char encrypted[size];
  int i;
  for (i = 0; i < size; i++)
    encrypted[i] = input[i] ^ key[i % (sizeof(key) / sizeof(char))];
  position = lseek(fd, 0L, SEEK_SET);
  printf("position: %ld\n", position);
  write(fd, encrypted, sizeof(encrypted));
  printf("%s was successfully encrypted/decrypted\n", filename);
}


x86 assembly (clang, -O0):
<encrypt_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movaps 0xe8f(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xe59(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <open_file@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
call   1030 <calculate_size@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rsi
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rdx
call   1080 <read@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
movslq -0x7c(%rbp),%rax
cmp    -0x60(%rbp),%rax
jae    1271 <encrypt_decrypt+0x101>
mov    -0x88(%rbp),%rax
mov    -0x68(%rbp),%rcx
movslq -0x7c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
movslq -0x7c(%rbp),%rdx
and    $0x3f,%rdx
movsbl -0x50(%rbp,%rdx,1),%edx
xor    %edx,%ecx
mov    %cl,%dl
movslq -0x7c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    122a <encrypt_decrypt+0xba>
mov    -0x54(%rbp),%edi
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <lseek@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x88(%rbp),%rsi
mov    -0x90(%rbp),%rax
mov    -0x54(%rbp),%edi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%rsi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x70(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt_decrypt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <open_file@plt>
mov    %eax,%r15d
mov    %eax,%edi
call   1030 <calculate_size@plt>
mov    %rax,%r12
lea    0xee6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    %r15d,%edi
mov    %rax,%rsi
mov    %r12,%rdx
call   1080 <read@plt>
mov    %rsp,%rbx
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %r12,%r12
je     12ed <encrypt_decrypt+0x17d>
lea    -0x41(%r12),%rax
cmp    $0xffffffffffffffc7,%rax
jae    11ea <encrypt_decrypt+0x7a>
xor    %eax,%eax
jmp    1280 <encrypt_decrypt+0x110>
cmp    $0x20,%r12
jae    11f4 <encrypt_decrypt+0x84>
xor    %eax,%eax
jmp    124f <encrypt_decrypt+0xdf>
mov    %r12,%rax
movups 0x0(%r13),%xmm0
movups 0x10(%r13),%xmm1
xorps  0xdf8(%rip),%xmm0
xorps  0xe01(%rip),%xmm1
and    $0xffffffffffffffe0,%rax
movaps %xmm0,(%rbx)
movaps %xmm1,0x10(%rbx)
cmp    $0x20,%rax
je     1240 <encrypt_decrypt+0xd0>
movups 0x20(%r13),%xmm0
movups 0x30(%r13),%xmm1
xorps  0xdef(%rip),%xmm0
xorps  0xdf8(%rip),%xmm1
movaps %xmm0,0x20(%rbx)
movaps %xmm1,0x30(%rbx)
cmp    %rax,%r12
je     12ed <encrypt_decrypt+0x17d>
test   $0x18,%r12b
je     1280 <encrypt_decrypt+0x110>
mov    %rax,%rcx
mov    %r12,%rax
and    $0xfffffffffffffff8,%rax
lea    0xde0(%rip),%rdx
mov    %ecx,%esi
and    $0x38,%esi
mov    (%rsi,%rdx,1),%rsi
xor    0x0(%r13,%rcx,1),%rsi
mov    %rsi,(%rbx,%rcx,1)
add    $0x8,%rcx
cmp    %rcx,%rax
jne    1260 <encrypt_decrypt+0xf0>
cmp    %rax,%r12
je     12ed <encrypt_decrypt+0x17d>
mov    %rax,%rcx
or     $0x1,%rcx
test   $0x1,%r12b
je     12a7 <encrypt_decrypt+0x137>
mov    %eax,%edx
and    $0x38,%edx
lea    0xda7(%rip),%rsi
mov    (%rdx,%rsi,1),%dl
xor    0x0(%r13,%rax,1),%dl
mov    %dl,(%rbx,%rax,1)
mov    %rcx,%rax
cmp    %rcx,%r12
je     12ed <encrypt_decrypt+0x17d>
lea    0xd8d(%rip),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edx
and    $0x3f,%edx
movzbl (%rdx,%rcx,1),%edx
xor    0x0(%r13,%rax,1),%dl
mov    %dl,(%rbx,%rax,1)
lea    0x1(%rax),%edx
and    $0x3f,%edx
movzbl (%rdx,%rcx,1),%edx
xor    0x1(%r13,%rax,1),%dl
mov    %dl,0x1(%rbx,%rax,1)
add    $0x2,%rax
cmp    %rax,%r12
jne    12c0 <encrypt_decrypt+0x150>
mov    0x2cec(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
lea    0xda0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1040 <write@plt>
lea    0xd90(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <printf@plt>

LLVM IR (-O0):
@__const.encrypt_decrypt.key = [64 x i8] c"nwWZTM5JSzaLD0WtQ8dGwInOlHfUhd7zY26Z8OKNFMlkJOnCr7I8QKu5752HyVPg"
@.str = [39 x i8] c"opened file with the size of %ld bytes\00"
@SEEK_SET = global i32 0
@.str.1 = [15 x i8] c"position: %ld\0A\00"
@.str.2 = [41 x i8] c"%s was successfully encrypted/decrypted\0A\00"
define void @encrypt_decrypt(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca [64 x i8]
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %2
%11 = bitcast [64 x i8]* %4 to i8*
%12 = load i8*, i8** %2
%13 = call i32 @open_file(i8* %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = call i64 @calculate_size(i32 %14)
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %16)
%18 = load i64, i64* %6
%19 = mul i64 %18, 1
%20 = call i64 @malloc(i64 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %7
%22 = load i32, i32* %5
%23 = load i8*, i8** %7
%24 = load i64, i64* %6
%25 = call i32 @read(i32 %22, i8* %23, i64 %24)
%26 = load i64, i64* %6
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %8
%28 = alloca i8, i64 %26
store i64 %26, i64* %9
store i32 0, i32* %10
br label %29
29: ; preds = %52, %1
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = load i64, i64* %6
%33 = icmp ult i64 %31, %32
br i1 %33, label %34, label %55
34: ; preds = %29
%35 = load i8*, i8** %7
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = urem i64 %42, 64
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = xor i32 %40, %46
%48 = trunc i32 %47 to i8
%49 = load i32, i32* %10
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %28, i64 %50
store i8 %48, i8* %51
br label %52
52: ; preds = %34
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %29
55: ; preds = %29
%56 = load i32, i32* %5
%57 = load i32, i32* @SEEK_SET
%58 = call i64 @lseek(i32 %56, i64 0, i32 %57)
store i64 %58, i64* %3
%59 = load i64, i64* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 %59)
%61 = load i32, i32* %5
%62 = trunc i64 %26 to i32
%63 = call i32 @write(i32 %61, i8* %28, i32 %62)
%64 = load i8*, i8** %2
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %64)
%66 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@__const.encrypt_decrypt.key = [64 x i8] c"nwWZTM5JSzaLD0WtQ8dGwInOlHfUhd7zY26Z8OKNFMlkJOnCr7I8QKu5752HyVPg"
@.str = [39 x i8] c"opened file with the size of %ld bytes\00"
@SEEK_SET = global i32 0
@.str.1 = [15 x i8] c"position: %ld\0A\00"
@.str.2 = [41 x i8] c"%s was successfully encrypted/decrypted\0A\00"
define void @encrypt_decrypt(i8* %0) {
%2 = tail call i32 @open_file(i8* %0)
%3 = tail call i64 @calculate_size(i32 %2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %3)
%5 = tail call i64 @malloc(i64 %3)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @read(i32 %2, i8* %6, i64 %3)
%8 = alloca i8, i64 %3
%9 = icmp eq i64 %3, 0
br i1 %9, label %101, label %10
10: ; preds = %1
%11 = add i64 %3, -65
%12 = icmp ult i64 %11, -57
br i1 %12, label %65, label %13
13: ; preds = %10
%14 = icmp ult i64 %3, 32
br i1 %14, label %46, label %15
15: ; preds = %13
%16 = and i64 %3, -32
%17 = inttoptr i64 %5 to <16 x i8>*
%18 = load <16 x i8>, <16 x i8>* %17
%19 = getelementptr inbounds i8, i8* %6, i64 16
%20 = bitcast i8* %19 to <16 x i8>*
%21 = load <16 x i8>, <16 x i8>* %20
%22 = xor <16 x i8> %18, <i8 110, i8 119, i8 87, i8 90, i8 84, i8 77, i8 53, i8 74, i8 83, i8 122, i8 97, i8 76, i8 68, i8 48, i8 87, i8 116>
%23 = xor <16 x i8> %21, <i8 81, i8 56, i8 100, i8 71, i8 119, i8 73, i8 110, i8 79, i8 108, i8 72, i8 102, i8 85, i8 104, i8 100, i8 55, i8 122>
%24 = bitcast i8* %8 to <16 x i8>*
store <16 x i8> %22, <16 x i8>* %24
%25 = getelementptr inbounds i8, i8* %8, i64 16
%26 = bitcast i8* %25 to <16 x i8>*
store <16 x i8> %23, <16 x i8>* %26
%27 = icmp eq i64 %16, 32
br i1 %27, label %41, label %28
28: ; preds = %15
%29 = getelementptr inbounds i8, i8* %6, i64 32
%30 = bitcast i8* %29 to <16 x i8>*
%31 = load <16 x i8>, <16 x i8>* %30
%32 = getelementptr inbounds i8, i8* %6, i64 48
%33 = bitcast i8* %32 to <16 x i8>*
%34 = load <16 x i8>, <16 x i8>* %33
%35 = xor <16 x i8> %31, <i8 89, i8 50, i8 54, i8 90, i8 56, i8 79, i8 75, i8 78, i8 70, i8 77, i8 108, i8 107, i8 74, i8 79, i8 110, i8 67>
%36 = xor <16 x i8> %34, <i8 114, i8 55, i8 73, i8 56, i8 81, i8 75, i8 117, i8 53, i8 55, i8 53, i8 50, i8 72, i8 121, i8 86, i8 80, i8 103>
%37 = getelementptr inbounds i8, i8* %8, i64 32
%38 = bitcast i8* %37 to <16 x i8>*
store <16 x i8> %35, <16 x i8>* %38
%39 = getelementptr inbounds i8, i8* %8, i64 48
%40 = bitcast i8* %39 to <16 x i8>*
store <16 x i8> %36, <16 x i8>* %40
br label %41
41: ; preds = %28, %15
%42 = icmp eq i64 %3, %16
br i1 %42, label %101, label %43
43: ; preds = %41
%44 = and i64 %3, 24
%45 = icmp eq i64 %44, 0
br i1 %45, label %65, label %46
46: ; preds = %13, %43
%47 = phi i64 [ %16, %43 ], [ 0, %13 ]
%48 = and i64 %3, -8
br label %49
49: ; preds = %49, %46
%50 = phi i64 [ %47, %46 ], [ %61, %49 ]
%51 = getelementptr inbounds i8, i8* %6, i64 %50
%52 = bitcast i8* %51 to <8 x i8>*
%53 = load <8 x i8>, <8 x i8>* %52
%54 = and i64 %50, 56
%55 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.encrypt_decrypt.key, i64 0, i64 %54
%56 = bitcast i8* %55 to <8 x i8>*
%57 = load <8 x i8>, <8 x i8>* %56
%58 = xor <8 x i8> %57, %53
%59 = getelementptr inbounds i8, i8* %8, i64 %50
%60 = bitcast i8* %59 to <8 x i8>*
store <8 x i8> %58, <8 x i8>* %60
%61 = add nuw i64 %50, 8
%62 = icmp eq i64 %61, %48
br i1 %62, label %63, label %49
63: ; preds = %49
%64 = icmp eq i64 %3, %48
br i1 %64, label %101, label %65
65: ; preds = %10, %43, %63
%66 = phi i64 [ 0, %10 ], [ %16, %43 ], [ %48, %63 ]
%67 = or i64 %66, 1
%68 = and i64 %3, 1
%69 = icmp eq i64 %68, 0
br i1 %69, label %79, label %70
70: ; preds = %65
%71 = getelementptr inbounds i8, i8* %6, i64 %66
%72 = load i8, i8* %71
%73 = and i64 %66, 56
%74 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.encrypt_decrypt.key, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = xor i8 %75, %72
%77 = getelementptr inbounds i8, i8* %8, i64 %66
store i8 %76, i8* %77
%78 = or i64 %66, 1
br label %79
79: ; preds = %70, %65
%80 = phi i64 [ %66, %65 ], [ %78, %70 ]
%81 = icmp eq i64 %3, %67
br i1 %81, label %101, label %82
82: ; preds = %79, %82
%83 = phi i64 [ %99, %82 ], [ %80, %79 ]
%84 = getelementptr inbounds i8, i8* %6, i64 %83
%85 = load i8, i8* %84
%86 = and i64 %83, 63
%87 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.encrypt_decrypt.key, i64 0, i64 %86
%88 = load i8, i8* %87
%89 = xor i8 %88, %85
%90 = getelementptr inbounds i8, i8* %8, i64 %83
store i8 %89, i8* %90
%91 = add nuw nsw i64 %83, 1
%92 = getelementptr inbounds i8, i8* %6, i64 %91
%93 = load i8, i8* %92
%94 = and i64 %91, 63
%95 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.encrypt_decrypt.key, i64 0, i64 %94
%96 = load i8, i8* %95
%97 = xor i8 %96, %93
%98 = getelementptr inbounds i8, i8* %8, i64 %91
store i8 %97, i8* %98
%99 = add nuw nsw i64 %83, 2
%100 = icmp eq i64 %99, %3
br i1 %100, label %101, label %82
101: ; preds = %79, %82, %41, %63, %1
%102 = load i32, i32* @SEEK_SET
%103 = tail call i64 @lseek(i32 %2, i64 0, i32 %102)
%104 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 %103)
%105 = trunc i64 %3 to i32
%106 = call i32 @write(i32 %2, i8* %8, i32 %105)
%107 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %0)
ret void
}