#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 __decrypt(char *filename, char *key) {
  FILE *file, *output;
  char c;
  size_t k = 0, keyLength;
  if (!checkExtension(filename, ".zze")) {
    printf("Error: The file \"%s\" isn't zze encrypted code.", filename);
    return 1;
  }
  requireUpperCases(key, "key");
  if (NULL == (file = openFile(filename, "r")))
    return 0;
  filename[strlen(filename) - 1] = 'z';
  output = fopen(filename, "w");
  keyLength = strlen(key);
  while (fscanf(file, "%c", &c) != EOF) {
    if (!requireUpperCase(c, "file"))
      return fclose(file), 1;
    c = (char)('A' + (26 + (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):
<__decrypt>:
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 <__decrypt+0x4d>
mov    -0x10(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133c <__decrypt+0x19c>
mov    -0x18(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1070 <requireUpperCases@plt>
mov    -0x10(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1040 <openFile@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    122b <__decrypt+0x8b>
movl   $0x0,-0x4(%rbp)
jmp    133c <__decrypt+0x19c>
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   $0x7a,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xde3(%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    0xdc2(%rip),%rsi
lea    -0x29(%rbp),%rdx
call   1080 <fscanf@plt>
mov    0x2d5e(%rip),%rcx
cmp    (%rcx),%rax
je     1323 <__decrypt+0x183>
lea    0xda5(%rip),%rsi
movsbl -0x29(%rbp),%edi
call   1090 <requireUpperCase@plt>
cmp    $0x0,%eax
jne    12c1 <__decrypt+0x121>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    133c <__decrypt+0x19c>
movsbl -0x29(%rbp),%eax
sub    $0x41,%eax
add    $0x1a,%eax
mov    -0x18(%rbp),%rcx
mov    -0x38(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x41,%ecx
sub    %ecx,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %dl,%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd45(%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     131e <__decrypt+0x17e>
movq   $0x0,-0x38(%rbp)
jmp    126f <__decrypt+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):
<__decrypt>:
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     12e4 <__decrypt+0x144>
lea    0xe68(%rip),%rsi
mov    %r13,%rdi
call   1070 <requireUpperCases@plt>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <openFile@plt>
mov    %rax,%rbp
xor    %eax,%eax
test   %rbp,%rbp
je     12f8 <__decrypt+0x158>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x7a,-0x1(%rax,%rbx,1)
lea    0xe33(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xe18(%rip),%rsi
lea    0x7(%rsp),%rdx
mov    %rbp,%rdi
call   1080 <fscanf@plt>
mov    0x2db0(%rip),%rbx
cmp    (%rbx),%rax
je     12d0 <__decrypt+0x130>
movslq %r14d,%r14
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movsbl 0x7(%rsp),%edi
lea    0xde3(%rip),%rsi
call   10a0 <requireUpperCase@plt>
test   %eax,%eax
je     1307 <__decrypt+0x167>
movsbl 0x7(%rsp),%eax
movsbl 0x0(%r13,%r12,1),%ecx
sub    %ecx,%eax
add    $0x1a,%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    0xd7b(%rip),%rsi
lea    0x7(%rsp),%rdx
call   1080 <fscanf@plt>
cmp    (%rbx),%rax
jne    1250 <__decrypt+0xb0>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    12f8 <__decrypt+0x158>
lea    0xd1a(%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    12f3 <__decrypt+0x153>

LLVM IR (-O0):
@.str = [5 x i8] c".zze\00"
@.str.1 = [47 x i8] c"Error: The file \22%s\22 isn't zze encrypted 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 @__decrypt(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 ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %77
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 %77
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 122, 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 = %71, %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 %72
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 %77
48: ; preds = %41
%49 = load i8, i8* %8
%50 = sext i8 %49 to i32
%51 = sub nsw i32 %50, 65
%52 = add nsw i32 26, %51
%53 = load i8*, i8** %5
%54 = load i64, i64* %9
%55 = getelementptr inbounds i8, i8* %53, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = sub nsw i32 %57, 65
%59 = sub nsw i32 %52, %58
%60 = srem i32 %59, 26
%61 = add nsw i32 65, %60
%62 = trunc i32 %61 to i8
store i8 %62, i8* %8
%63 = load i32*, i32** %7
%64 = load i8, i8* %8
%65 = call i32 @fprintf(i32* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8 signext %64)
%66 = load i64, i64* %9
%67 = add i64 %66, 1
store i64 %67, i64* %9
%68 = load i64, i64* %10
%69 = icmp uge i64 %67, %68
br i1 %69, label %70, label %71
70: ; preds = %48
store i64 0, i64* %9
br label %71
71: ; preds = %70, %48
br label %36
72: ; preds = %36
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
store i32 0, i32* %3
br label %77
77: ; preds = %72, %45, %23, %14
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [5 x i8] c".zze\00"
@.str.1 = [47 x i8] c"Error: The file \22%s\22 isn't zze encrypted 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 @__decrypt(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 ([47 x i8], [47 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 122, 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, 26
%37 = sub 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
}