#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 */
int /*<<< orphan*/ decrypter(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ next_key(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int _Problem059(void) {
  char key[4];
  FILE *ciphertext;
  strcpy(key, "aaa");
  ciphertext = fopen("files/cipher1.txt", "r");
  if (ciphertext == (FILE *)NULL) {
    perror("059: Cannot open files/cipher1.txt for reading\n");
    return 2;
  }
  do {
    rewind(ciphertext);
    decrypter(key, ciphertext);
    next_key(key);
  } while (strcmp(key, "aaa"));
  fclose(ciphertext);
  return 1;
}


x86 assembly (clang, -O0):
<_Problem059>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xe65(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d2 <_Problem059+0x52>
lea    0xe57(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1220 <_Problem059+0xa0>
jmp    11d7 <_Problem059+0x57>
mov    -0x10(%rbp),%rdi
call   1070 <rewind@plt>
lea    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <decrypter@plt>
lea    -0x8(%rbp),%rdi
call   1030 <next_key@plt>
lea    -0x8(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11d7 <_Problem059+0x57>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_Problem059>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe70(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1040 <strcpy@plt>
lea    0xe63(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1212 <_Problem059+0x92>
mov    %rax,%rbx
lea    0xc(%rsp),%r14
lea    0xe3f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <rewind@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <decrypter@plt>
mov    %r14,%rdi
call   1030 <next_key@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11d0 <_Problem059+0x50>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdff(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%eax
jmp    1208 <_Problem059+0x88>

LLVM IR (-O0):
@.str = [4 x i8] c"aaa\00"
@.str.1 = [18 x i8] c"files/cipher1.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [48 x i8] c"059: Cannot open files/cipher1.txt for reading\0A\00"
define i32 @_Problem059() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca i32*
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %1
br label %27
11: ; preds = %0
br label %12
12: ; preds = %20, %11
%13 = load i32*, i32** %3
%14 = call i32 @rewind(i32* %13)
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i32 @decrypter(i8* %15, i32* %16)
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%19 = call i32 @next_key(i8* %18)
br label %20
20: ; preds = %12
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %12, label %24
24: ; preds = %20
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
store i32 1, i32* %1
br label %27
27: ; preds = %24, %9
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"aaa\00"
@.str.1 = [18 x i8] c"files/cipher1.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [48 x i8] c"059: Cannot open files/cipher1.txt for reading\0A\00"
define i32 @_Problem059() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
br label %16
8: ; preds = %0, %8
%9 = call i32 @rewind(i32* %4)
%10 = call i32 @decrypter(i8* %2, i32* %4)
%11 = call i32 @next_key(i8* %2)
%12 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = call i32 @fclose(i32* %4)
br label %16
16: ; preds = %14, %6
%17 = phi i32 [ 2, %6 ], [ 1, %14 ]
ret i32 %17
}