#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int writeKeyPairToFile(const char *fileName, const char *keyPair) {
  FILE *file;
  file = fopen(fileName, "w");
  if (file == NULL) {
    printf("Could not open file '%s' for writing keypair\n", fileName);
    return -1;
  }
  fputs(keyPair, file);
  if (ferror(file) != 0) {
    fclose(file);
    printf("Error writing keypair to file '%s'.\n", fileName);
    return -1;
  }
  fclose(file);
  printf("Wrote keypair '%s' to file '%s'.\n", keyPair, fileName);
  return 0;
}


x86 assembly (clang, -O0):
<writeKeyPairToFile>:
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 <writeKeyPairToFile+0x4d>
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <writeKeyPairToFile+0xba>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11e4 <writeKeyPairToFile+0x94>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <writeKeyPairToFile+0xba>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe59(%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):
<writeKeyPairToFile>:
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     119e <writeKeyPairToFile+0x4e>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r12,%r12
je     11b6 <writeKeyPairToFile+0x66>
lea    0xe94(%rip),%rdi
jmp    11a5 <writeKeyPairToFile+0x55>
lea    0xe5d(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%ebx
jmp    11cc <writeKeyPairToFile+0x7c>
lea    0xe98(%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"w\00"
@.str.1 = [46 x i8] c"Could not open file '%s' for writing keypair\0A\00"
@.str.2 = [37 x i8] c"Error writing keypair to file '%s'.\0A\00"
@.str.3 = [34 x i8] c"Wrote keypair '%s' to file '%s'.\0A\00"
define i32 @writeKeyPairToFile(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 %32
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = load i32*, i32** %6
%17 = call i32 @fputs(i8* %15, i32* %16)
%18 = load i32*, i32** %6
%19 = call i64 @ferror(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
%24 = load i8*, i8** %4
%25 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32 -1, i32* %3
br label %32
26: ; preds = %14
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
%29 = load i8*, i8** %5
%30 = load i8*, i8** %4
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %29, i8* %30)
store i32 0, i32* %3
br label %32
32: ; preds = %26, %21, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [46 x i8] c"Could not open file '%s' for writing keypair\0A\00"
@.str.2 = [37 x i8] c"Error writing keypair to file '%s'.\0A\00"
@.str.3 = [34 x i8] c"Wrote keypair '%s' to file '%s'.\0A\00"
define i32 @writeKeyPairToFile(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 %16
7: ; preds = %2
%8 = tail call i32 @fputs(i8* %1, i32* %3)
%9 = tail call i64 @ferror(i32* %3)
%10 = icmp eq i64 %9, 0
%11 = tail call i32 @fclose(i32* %3)
br i1 %10, label %14, label %12
12: ; preds = %7
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %16
14: ; preds = %7
%15 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %0)
br label %16
16: ; preds = %14, %12, %5
%17 = phi i32 [ -1, %5 ], [ -1, %12 ], [ 0, %14 ]
ret i32 %17
}