#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 */
char *concat(char const *, char *, char const *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *e_fopen(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *read_file(int /*<<< orphan*/ *);
char *read_ship_file(const char *root_dir, const char *ship_name, int is_alien,
                     const char *turn) {
  FILE *fp;
  char *file;
  char *s;
  if (is_alien) {
    fp = e_fopen(s = concat(root_dir, "/", ship_name, ".html", NULL), "r");
  } else {
    fp = e_fopen(s = concat(root_dir, "/", ship_name, ".html", NULL), "r");
  }
  free(s);
  file = read_file(fp);
  fclose(fp);
  return file;
}


x86 assembly (clang, -O0):
<read_ship_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ad <read_ship_file+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe80(%rip),%rsi
lea    0xe7b(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <concat@plt>
mov    %rax,%rdi
mov    %rdi,-0x38(%rbp)
lea    0xe69(%rip),%rsi
call   1040 <e_fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    11e4 <read_ship_file+0x94>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe44(%rip),%rsi
lea    0xe3f(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <concat@plt>
mov    %rax,%rdi
mov    %rdi,-0x38(%rbp)
lea    0xe2d(%rip),%rsi
call   1040 <e_fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1070 <read_file@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ship_file>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rdx
lea    0xea2(%rip),%rsi
lea    0xe9d(%rip),%rcx
xor    %r8d,%r8d
call   1060 <concat@plt>
mov    %rax,%rbx
lea    0xe91(%rip),%rsi
mov    %rax,%rdi
call   1040 <e_fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1070 <read_file@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [6 x i8] c".html\00"
@.str.2 = [2 x i8] c"r\00"
define i8* @read_ship_file(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i8* @concat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* null)
store i8* %17, i8** %11
%18 = call i32* @e_fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %9
br label %24
19: ; preds = %4
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = call i8* @concat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* null)
store i8* %22, i8** %11
%23 = call i32* @e_fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %9
br label %24
24: ; preds = %19, %14
%25 = load i8*, i8** %11
%26 = call i32 @free(i8* %25)
%27 = load i32*, i32** %9
%28 = call i8* @read_file(i32* %27)
store i8* %28, i8** %10
%29 = load i32*, i32** %9
%30 = call i32 @fclose(i32* %29)
%31 = load i8*, i8** %10
ret i8* %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [6 x i8] c".html\00"
@.str.2 = [2 x i8] c"r\00"
define i8* @read_ship_file(i8* %0, i8* %1, i32 %2, i8* nocapture readnone %3) {
%5 = tail call i8* @concat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* null)
%6 = tail call i32* @e_fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @free(i8* %5)
%8 = tail call i8* @read_file(i32* %6)
%9 = tail call i32 @fclose(i32* %6)
ret i8* %8
}