#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*/ BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int readKeyPairFromFile(const char *fileName, char *keyPair) {
  FILE *file;
  file = fopen(fileName, "r");
  if (file == NULL) {
    printf("Could not open file '%s' for reading keypair\n", fileName);
    return -1;
  }
  fgets(keyPair, BUFSIZ, file);
  if (ferror(file) != 0) {
    fclose(file);
    printf("Error reading keypair from file '%s'.\n", fileName);
    return -1;
  }
  fclose(file);
  printf("Read keypair '%s' from file '%s'.\n", keyPair, fileName);
  return 0;
}


x86 assembly (clang, -O0):
<readKeyPairFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119d <readKeyPairFromFile+0x4d>
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <readKeyPairFromFile+0xc3>
mov    -0x18(%rbp),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
call   1060 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ed <readKeyPairFromFile+0x9d>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <readKeyPairFromFile+0xc3>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readKeyPairFromFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a7 <readKeyPairFromFile+0x57>
mov    %rax,%rbx
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r12,%r12
je     11bf <readKeyPairFromFile+0x6f>
lea    0xe8b(%rip),%rdi
jmp    11ae <readKeyPairFromFile+0x5e>
lea    0xe54(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%ebx
jmp    11d5 <readKeyPairFromFile+0x85>
lea    0xe91(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [46 x i8] c"Could not open file '%s' for reading keypair\0A\00"
@BUFSIZ = global i32 0
@.str.2 = [39 x i8] c"Error reading keypair from file '%s'.\0A\00"
@.str.3 = [35 x i8] c"Read keypair '%s' from file '%s'.\0A\00"
define i32 @readKeyPairFromFile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i32 -1, i32* %3
br label %33
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = load i32, i32* @BUFSIZ
%17 = load i32*, i32** %6
%18 = call i32 @fgets(i8* %15, i32 %16, i32* %17)
%19 = load i32*, i32** %6
%20 = call i64 @ferror(i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
%25 = load i8*, i8** %4
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %25)
store i32 -1, i32* %3
br label %33
27: ; preds = %14
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %5
%31 = load i8*, i8** %4
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %30, i8* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %27, %22, %11
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [46 x i8] c"Could not open file '%s' for reading keypair\0A\00"
@BUFSIZ = global i32 0
@.str.2 = [39 x i8] c"Error reading keypair from file '%s'.\0A\00"
@.str.3 = [35 x i8] c"Read keypair '%s' from file '%s'.\0A\00"
define i32 @readKeyPairFromFile(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %17
7: ; preds = %2
%8 = load i32, i32* @BUFSIZ
%9 = tail call i32 @fgets(i8* %1, i32 %8, i32* %3)
%10 = tail call i64 @ferror(i32* %3)
%11 = icmp eq i64 %10, 0
%12 = tail call i32 @fclose(i32* %3)
br i1 %11, label %15, label %13
13: ; preds = %7
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %17
15: ; preds = %7
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %0)
br label %17
17: ; preds = %15, %13, %5
%18 = phi i32 [ -1, %5 ], [ -1, %13 ], [ 0, %15 ]
ret i32 %18
}