#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ name_ext(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
FILE *fileOpen(char *file, char *ext, int append) {
  FILE *fp;
  char filename[1024];
  strcpy(filename, file);
  name_ext(filename, ext);
  if (append)
    fp = fopen(filename, "a");
  else
    fp = fopen(filename, "w");
  assert(fp != NULL);
  return fp;
}


x86 assembly (clang, -O0):
<fileOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <name_ext@plt>
cmpl   $0x0,-0x14(%rbp)
je     119c <fileOpen+0x5c>
lea    -0x420(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    11b3 <fileOpen+0x73>
lea    -0x420(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileOpen>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <name_ext@plt>
test   %ebp,%ebp
lea    0xe90(%rip),%rax
lea    0xe87(%rip),%rsi
cmove  %rax,%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"w\00"
define i32* @fileOpen(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = call i32 @name_ext(i8* %12, i8* %13)
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %7
br label %23
20: ; preds = %3
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %7
br label %23
23: ; preds = %20, %17
%24 = load i32*, i32** %7
%25 = icmp ne i32* %24, null
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i32*, i32** %7
ret i32* %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"w\00"
define i32* @fileOpen(i8* %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = call i32 @name_ext(i8* %5, i8* %1)
%8 = icmp eq i32 %2, 0
%9 = select i1 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%10 = call i32* @fopen(i8* %5, i8* %9)
%11 = icmp ne i32* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
ret i32* %10
}