#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*/ *);
int /*<<< orphan*/ *fopen(char const *, char const *);
int openFiles(FILE **inputFile, const char *inputFilename,
              const char *inputMode, FILE **outputFile,
              const char *outputFilename, const char *outputMode) {
  *inputFile = NULL;
  *outputFile = NULL;
  if (inputFilename != NULL &&
      (*inputFile = fopen(inputFilename, inputMode)) == NULL) {
    ;
    return -1;
  }
  if (outputFilename != NULL &&
      (*outputFile = fopen(outputFilename, outputMode)) == NULL) {
    if (*inputFile != NULL) {
      fclose(*inputFile);
      *inputFile = NULL;
    };
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<openFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     118b <openFiles+0x6b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fopen@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    118b <openFiles+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <openFiles+0xcc>
cmpq   $0x0,-0x30(%rbp)
je     11e5 <openFiles+0xc5>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <fopen@plt>
mov    -0x28(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11e5 <openFiles+0xc5>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d9 <openFiles+0xb9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <openFiles+0xcc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openFiles>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r9,%r15
mov    %r8,%rbx
mov    %rcx,%rbp
mov    %rdi,%r12
movq   $0x0,(%rdi)
movq   $0x0,(%rcx)
test   %rsi,%rsi
je     115b <openFiles+0x3b>
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <fopen@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1195 <openFiles+0x75>
xor    %r14d,%r14d
test   %rbx,%rbx
je     119b <openFiles+0x7b>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fopen@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
jne    119b <openFiles+0x7b>
mov    (%r12),%rdi
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     119b <openFiles+0x7b>
call   1030 <fclose@plt>
movq   $0x0,(%r12)
jmp    119b <openFiles+0x7b>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @openFiles(i32** %0, i8* %1, i8* %2, i32** %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32**
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32**
%12 = alloca i8*
%13 = alloca i8*
store i32** %0, i32*** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i32** %3, i32*** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
%14 = load i32**, i32*** %8
store i32* null, i32** %14
%15 = load i32**, i32*** %11
store i32* null, i32** %15
%16 = load i8*, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %25
18: ; preds = %6
%19 = load i8*, i8** %9
%20 = load i8*, i8** %10
%21 = call i32* @fopen(i8* %19, i8* %20)
%22 = load i32**, i32*** %8
store i32* %21, i32** %22
%23 = icmp eq i32* %21, null
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 -1, i32* %7
br label %45
25: ; preds = %18, %6
%26 = load i8*, i8** %12
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %44
28: ; preds = %25
%29 = load i8*, i8** %12
%30 = load i8*, i8** %13
%31 = call i32* @fopen(i8* %29, i8* %30)
%32 = load i32**, i32*** %11
store i32* %31, i32** %32
%33 = icmp eq i32* %31, null
br i1 %33, label %34, label %44
34: ; preds = %28
%35 = load i32**, i32*** %8
%36 = load i32*, i32** %35
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i32**, i32*** %8
%40 = load i32*, i32** %39
%41 = call i32 @fclose(i32* %40)
%42 = load i32**, i32*** %8
store i32* null, i32** %42
br label %43
43: ; preds = %38, %34
store i32 -1, i32* %7
br label %45
44: ; preds = %28, %25
store i32 0, i32* %7
br label %45
45: ; preds = %44, %43, %24
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
define i32 @openFiles(i32** nocapture %0, i8* %1, i8* nocapture %2, i32** nocapture writeonly %3, i8* %4, i8* nocapture %5) {
store i32* null, i32** %0
store i32* null, i32** %3
%7 = icmp eq i8* %1, null
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = tail call i32* @fopen(i8* %1, i8* %2)
store i32* %9, i32** %0
%10 = icmp eq i32* %9, null
br i1 %10, label %21, label %11
11: ; preds = %8, %6
%12 = icmp eq i8* %4, null
br i1 %12, label %21, label %13
13: ; preds = %11
%14 = tail call i32* @fopen(i8* %4, i8* %5)
store i32* %14, i32** %3
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32*, i32** %0
%18 = icmp eq i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @fclose(i32* %17)
store i32* null, i32** %0
br label %21
21: ; preds = %11, %13, %16, %19, %8
%22 = phi i32 [ -1, %8 ], [ -1, %19 ], [ -1, %16 ], [ 0, %13 ], [ 0, %11 ]
ret i32 %22
}