#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 */
scalar_t__ EOF;
int /*<<< orphan*/ checkExtension(char *, char *);
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ *openFile(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ requireUpperCase(char, char *);
int /*<<< orphan*/ requireUpperCases(char *, char *);
int strlen(char *);
int __encrypt(char *filename, char *key) {
  FILE *file, *output;
  char c;
  size_t k = 0, keyLength;
  if (!checkExtension(filename, ".zzz")) {
    printf("Error: The file \"%s\" isn't zzz executable code.", filename);
    return 1;
  }
  requireUpperCases(key, "key");
  if (NULL == (file = openFile(filename, "r")))
    return 0;
  filename[strlen(filename) - 1] = 'e';
  output = fopen(filename, "w");
  keyLength = strlen(key);
  while (fscanf(file, "%c", &c) != EOF) {
    if (!requireUpperCase(c, "file"))
      return fclose(file), 1;
    c = (char)('A' + ((c - 'A') + (key[k] - 'A')) % 26);
    fprintf(output, "%c", c);
    if (++k >= keyLength)
      k = 0;
  }
  fclose(file);
  fclose(output);
  return 0;
}


x86 assembly (clang, -O0):
<__encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   10c0 <checkExtension@plt>
cmp    $0x0,%eax
jne    11ed <__encrypt+0x4d>
mov    -0x10(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1339 <__encrypt+0x199>
mov    -0x18(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <requireUpperCases@plt>
mov    -0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1040 <openFile@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    122b <__encrypt+0x8b>
movl   $0x0,-0x4(%rbp)
jmp    1339 <__encrypt+0x199>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x65,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdc3(%rip),%rsi
lea    -0x29(%rbp),%rdx
call   1080 <fscanf@plt>
mov    0x2d5e(%rip),%rcx
cmp    (%rcx),%rax
je     1320 <__encrypt+0x180>
lea    0xda6(%rip),%rsi
movsbl -0x29(%rbp),%edi
call   1090 <requireUpperCase@plt>
cmp    $0x0,%eax
jne    12c1 <__encrypt+0x121>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1339 <__encrypt+0x199>
movsbl -0x29(%rbp),%eax
sub    $0x41,%eax
mov    -0x18(%rbp),%rcx
mov    -0x38(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x41,%ecx
add    %ecx,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %dl,%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd49(%rip),%rsi
movsbl -0x29(%rbp),%edx
call   10a0 <fprintf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
cmp    -0x40(%rbp),%rax
jb     131b <__encrypt+0x17b>
movq   $0x0,-0x38(%rbp)
jmp    126f <__encrypt+0xcf>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xe48(%rip),%rsi
call   10c0 <checkExtension@plt>
test   %eax,%eax
je     12ea <__encrypt+0x14a>
lea    0xe69(%rip),%rsi
mov    %r13,%rdi
call   1070 <requireUpperCases@plt>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <openFile@plt>
mov    %rax,%rbp
xor    %eax,%eax
test   %rbp,%rbp
je     12fe <__encrypt+0x15e>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x65,-0x1(%rax,%rbx,1)
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xe19(%rip),%rsi
lea    0x7(%rsp),%rdx
mov    %rbp,%rdi
call   1080 <fscanf@plt>
mov    0x2db0(%rip),%rbx
cmp    (%rbx),%rax
je     12d6 <__encrypt+0x136>
movslq %r14d,%r14
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movsbl 0x7(%rsp),%edi
lea    0xde4(%rip),%rsi
call   10a0 <requireUpperCase@plt>
test   %eax,%eax
je     130d <__encrypt+0x16d>
movsbl 0x7(%rsp),%eax
movsbl 0x0(%r13,%r12,1),%ecx
add    %ecx,%eax
add    $0xffffff7e,%eax
movswl %ax,%ecx
imul   $0x4ec5,%ecx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x13,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,0x7(%rsp)
movzbl %al,%edi
mov    %r15,%rsi
call   1090 <fputc@plt>
add    $0x1,%r12
cmp    %r14,%r12
mov    $0x0,%eax
cmovae %rax,%r12
mov    %rbp,%rdi
lea    0xd7a(%rip),%rsi
lea    0x7(%rsp),%rdx
call   1080 <fscanf@plt>
cmp    (%rbx),%rax
jne    1250 <__encrypt+0xb0>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    12fe <__encrypt+0x15e>
lea    0xd14(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    12f9 <__encrypt+0x159>

LLVM IR (-O0):
@.str = [5 x i8] c".zzz\00"
@.str.1 = [48 x i8] c"Error: The file \22%s\22 isn't zzz executable code.\00"
@.str.2 = [4 x i8] c"key\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.6 = [5 x i8] c"file\00"
define i32 @__encrypt(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 0, i64* %9
%11 = load i8*, i8** %4
%12 = call i32 @checkExtension(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %76
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i32 @requireUpperCases(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = load i8*, i8** %4
%21 = call i32* @openFile(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %21, i32** %6
%22 = icmp eq i32* null, %21
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 0, i32* %3
br label %76
24: ; preds = %17
%25 = load i8*, i8** %4
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
store i8 101, i8* %30
%31 = load i8*, i8** %4
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
store i64 %35, i64* %10
br label %36
36: ; preds = %70, %24
%37 = load i32*, i32** %6
%38 = call i64 @fscanf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%39 = load i64, i64* @EOF
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %71
41: ; preds = %36
%42 = load i8, i8* %8
%43 = call i32 @requireUpperCase(i8 signext %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
store i32 1, i32* %3
br label %76
48: ; preds = %41
%49 = load i8, i8* %8
%50 = sext i8 %49 to i32
%51 = sub nsw i32 %50, 65
%52 = load i8*, i8** %5
%53 = load i64, i64* %9
%54 = getelementptr inbounds i8, i8* %52, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = sub nsw i32 %56, 65
%58 = add nsw i32 %51, %57
%59 = srem i32 %58, 26
%60 = add nsw i32 65, %59
%61 = trunc i32 %60 to i8
store i8 %61, i8* %8
%62 = load i32*, i32** %7
%63 = load i8, i8* %8
%64 = call i32 @fprintf(i32* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8 signext %63)
%65 = load i64, i64* %9
%66 = add i64 %65, 1
store i64 %66, i64* %9
%67 = load i64, i64* %10
%68 = icmp uge i64 %66, %67
br i1 %68, label %69, label %70
69: ; preds = %48
store i64 0, i64* %9
br label %70
70: ; preds = %69, %48
br label %36
71: ; preds = %36
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %71, %45, %23, %14
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [5 x i8] c".zzz\00"
@.str.1 = [48 x i8] c"Error: The file \22%s\22 isn't zzz executable code.\00"
@.str.2 = [4 x i8] c"key\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.6 = [5 x i8] c"file\00"
define i32 @__encrypt(i8* %0, i8* %1) {
%3 = alloca i8
%4 = tail call i32 @checkExtension(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %52
8: ; preds = %2
%9 = tail call i32 @requireUpperCases(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32* @openFile(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %52, label %12
12: ; preds = %8
%13 = tail call i32 @strlen(i8* %0)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 101, i8* %16
%17 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 @strlen(i8* %1)
%19 = sext i32 %18 to i64
%20 = call i64 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
br i1 %22, label %49, label %23
23: ; preds = %12, %30
%24 = phi i64 [ %45, %30 ], [ 0, %12 ]
%25 = load i8, i8* %3
%26 = call i32 @requireUpperCase(i8 signext %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @fclose(i32* %10)
br label %52
30: ; preds = %23
%31 = load i8, i8* %3
%32 = sext i8 %31 to i16
%33 = getelementptr inbounds i8, i8* %1, i64 %24
%34 = load i8, i8* %33
%35 = sext i8 %34 to i16
%36 = add nsw i16 %32, -130
%37 = add nsw i16 %36, %35
%38 = srem i16 %37, 26
%39 = trunc i16 %38 to i8
%40 = add nsw i8 %39, 65
store i8 %40, i8* %3
%41 = zext i8 %40 to i32
%42 = call i32 @fputc(i32 %41, i32* %17)
%43 = add i64 %24, 1
%44 = icmp ult i64 %43, %19
%45 = select i1 %44, i64 %43, i64 0
%46 = call i64 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%47 = load i64, i64* @EOF
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %23
49: ; preds = %30, %12
%50 = call i32 @fclose(i32* %10)
%51 = call i32 @fclose(i32* %17)
br label %52
52: ; preds = %8, %49, %28, %6
%53 = phi i32 [ 1, %28 ], [ 0, %49 ], [ 1, %6 ], [ 0, %8 ]
ret i32 %53
}