#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *gms_malloc(size_t);
scalar_t__ gms_strcasecmp(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
void gms_establish_filenames(char *name, char **text, char **graphics,
                             char **hints) {
  char *base, *text_file, *graphics_file, *hints_file;
  FILE *stream;
  assert(name && text && graphics && hints);
  base = gms_malloc(strlen(name) + 1);
  strcpy(base, name);
  if (strlen(base) > strlen(".XXX")) {
    if (gms_strcasecmp(base + strlen(base) - strlen(".MAG"), ".MAG") == 0 ||
        gms_strcasecmp(base + strlen(base) - strlen(".GFX"), ".GFX") == 0 ||
        gms_strcasecmp(base + strlen(base) - strlen(".HNT"), ".HNT") == 0)
      base[strlen(base) - strlen(".XXX")] = '\0';
  }
  text_file = gms_malloc(strlen(base) + strlen(".MAG") + 1);
  strcpy(text_file, base);
  strcat(text_file, ".MAG");
  stream = fopen(text_file, "rb");
  if (!stream) {
    strcpy(text_file, base);
    strcat(text_file, ".mag");
    stream = fopen(text_file, "rb");
    if (!stream) {
      *text = NULL;
      *graphics = NULL;
      *hints = NULL;
      free(text_file);
      free(base);
      return;
    }
  }
  if (stream)
    fclose(stream);
  graphics_file = gms_malloc(strlen(base) + strlen(".GFX") + 1);
  strcpy(graphics_file, base);
  strcat(graphics_file, ".GFX");
  stream = fopen(graphics_file, "rb");
  if (!stream) {
    strcpy(graphics_file, base);
    strcat(graphics_file, ".gfx");
    stream = fopen(graphics_file, "rb");
    if (!stream) {
      free(graphics_file);
      graphics_file = NULL;
    }
  }
  if (stream)
    fclose(stream);
  hints_file = gms_malloc(strlen(base) + strlen(".HNT") + 1);
  strcpy(hints_file, base);
  strcat(hints_file, ".HNT");
  stream = fopen(hints_file, "rb");
  if (!stream) {
    strcpy(hints_file, base);
    strcat(hints_file, ".hnt");
    stream = fopen(hints_file, "rb");
    if (!stream) {
      free(hints_file);
      hints_file = NULL;
    }
  }
  if (stream)
    fclose(stream);
  *text = text_file;
  *graphics = graphics_file;
  *hints = hints_file;
  free(base);
}


x86 assembly (clang, -O0):
<gms_establish_filenames>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x49(%rbp)
je     11e6 <gms_establish_filenames+0x56>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x49(%rbp)
je     11e6 <gms_establish_filenames+0x56>
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x49(%rbp)
je     11e6 <gms_establish_filenames+0x56>
cmpq   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <gms_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x58(%rbp)
lea    0xdd3(%rip),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
cmp    %rcx,%rax
jbe    137c <gms_establish_filenames+0x1ec>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
lea    0xd9d(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
lea    0xd82(%rip),%rsi
call   1090 <gms_strcasecmp@plt>
cmp    $0x0,%rax
je     1338 <gms_establish_filenames+0x1a8>
mov    -0x28(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x70(%rbp)
lea    0xd52(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    %rax,%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
lea    0xd37(%rip),%rsi
call   1090 <gms_strcasecmp@plt>
cmp    $0x0,%rax
je     1338 <gms_establish_filenames+0x1a8>
mov    -0x28(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x80(%rbp)
lea    0xd01(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    %rax,%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
lea    0xce6(%rip),%rsi
call   1090 <gms_strcasecmp@plt>
cmp    $0x0,%rax
jne    1377 <gms_establish_filenames+0x1e7>
mov    -0x28(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x98(%rbp)
lea    0xca6(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x98(%rbp),%rcx
mov    %rax,%rdx
mov    -0x90(%rbp),%rax
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    137c <gms_establish_filenames+0x1ec>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0xa0(%rbp)
lea    0xc72(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xa0(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <gms_malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xc3e(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xc3d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1464 <gms_establish_filenames+0x2d4>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xc14(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xc01(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    145f <gms_establish_filenames+0x2cf>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    164c <gms_establish_filenames+0x4bc>
jmp    1464 <gms_establish_filenames+0x2d4>
cmpq   $0x0,-0x48(%rbp)
je     1478 <gms_establish_filenames+0x2e8>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0xa8(%rbp)
lea    0xb7b(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xa8(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <gms_malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xb47(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xb41(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1539 <gms_establish_filenames+0x3a9>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xb1d(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xb05(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1534 <gms_establish_filenames+0x3a4>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x38(%rbp)
jmp    1539 <gms_establish_filenames+0x3a9>
cmpq   $0x0,-0x48(%rbp)
je     154d <gms_establish_filenames+0x3bd>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0xb0(%rbp)
lea    0xaab(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xb0(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <gms_malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    0xa77(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x40(%rbp),%rdi
lea    0xa6c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    160e <gms_establish_filenames+0x47e>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    0xa4d(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x40(%rbp),%rdi
lea    0xa30(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1609 <gms_establish_filenames+0x479>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x40(%rbp)
jmp    160e <gms_establish_filenames+0x47e>
cmpq   $0x0,-0x48(%rbp)
je     1622 <gms_establish_filenames+0x492>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gms_establish_filenames>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbp
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
test   %rdx,%rdx
setne  %al
test   %r14,%r14
setne  %dl
and    %al,%dl
and    %cl,%dl
movzbl %dl,%edi
call   1080 <assert@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <gms_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x5,%rax
jb     1262 <gms_establish_filenames+0xd2>
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xdf7(%rip),%rsi
call   1090 <gms_strcasecmp@plt>
test   %rax,%rax
je     1255 <gms_establish_filenames+0xc5>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xddb(%rip),%rsi
call   1090 <gms_strcasecmp@plt>
test   %rax,%rax
je     1255 <gms_establish_filenames+0xc5>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xdbf(%rip),%rsi
call   1090 <gms_strcasecmp@plt>
test   %rax,%rax
jne    1262 <gms_establish_filenames+0xd2>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movb   $0x0,-0x4(%rax,%rbx,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x5(%rax),%rdi
call   1070 <gms_malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xd78(%rip),%rsi
mov    %r13,%rdi
call   10b0 <strcat@plt>
lea    0xd78(%rip),%rsi
mov    %r13,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
jne    12d6 <gms_establish_filenames+0x146>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xd5c(%rip),%rsi
mov    %r13,%rdi
call   10b0 <strcat@plt>
lea    0xd4a(%rip),%rsi
mov    %r13,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     13fd <gms_establish_filenames+0x26d>
mov    %r15,(%rsp)
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x5(%rax),%rdi
call   1070 <gms_malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xcfd(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcat@plt>
lea    0xcf8(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
jne    1356 <gms_establish_filenames+0x1c6>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xce1(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcat@plt>
lea    0xcca(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     141d <gms_establish_filenames+0x28d>
mov    %r14,%r15
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x5(%rax),%rdi
call   1070 <gms_malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xc83(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xc79(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
jne    13d1 <gms_establish_filenames+0x241>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xc67(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xc4b(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     142f <gms_establish_filenames+0x29f>
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    %r13,(%r12)
mov    (%rsp),%rax
mov    %rbp,(%rax)
mov    %r14,(%r15)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
movq   $0x0,(%r12)
movq   $0x0,(%r15)
movq   $0x0,(%r14)
mov    %r13,%rdi
call   1030 <free@plt>
jmp    13e7 <gms_establish_filenames+0x257>
mov    %r14,%r15
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
jmp    1361 <gms_establish_filenames+0x1d1>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
jmp    13d9 <gms_establish_filenames+0x249>

LLVM IR (-O0):
@.str = [5 x i8] c".XXX\00"
@.str.1 = [5 x i8] c".MAG\00"
@.str.2 = [5 x i8] c".GFX\00"
@.str.3 = [5 x i8] c".HNT\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [5 x i8] c".mag\00"
@.str.6 = [5 x i8] c".gfx\00"
@.str.7 = [5 x i8] c".hnt\00"
define void @gms_establish_filenames(i8* %0, i8** %1, i8** %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i8** %3, i8*** %8
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %25
16: ; preds = %4
%17 = load i8**, i8*** %6
%18 = icmp ne i8** %17, null
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i8**, i8*** %7
%21 = icmp ne i8** %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8**, i8*** %8
%24 = icmp ne i8** %23, null
br label %25
25: ; preds = %22, %19, %16, %4
%26 = phi i1 [ false, %19 ], [ false, %16 ], [ false, %4 ], [ %24, %22 ]
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i8*, i8** %5
%30 = call i64 @strlen(i8* %29)
%31 = add i64 %30, 1
%32 = call i8* @gms_malloc(i64 %31)
store i8* %32, i8** %9
%33 = load i8*, i8** %9
%34 = load i8*, i8** %5
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %9
%37 = call i64 @strlen(i8* %36)
%38 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%39 = icmp ugt i64 %37, %38
br i1 %39, label %40, label %78
40: ; preds = %25
%41 = load i8*, i8** %9
%42 = load i8*, i8** %9
%43 = call i64 @strlen(i8* %42)
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%46 = sub i64 0, %45
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = call i64 @gms_strcasecmp(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %70, label %50
50: ; preds = %40
%51 = load i8*, i8** %9
%52 = load i8*, i8** %9
%53 = call i64 @strlen(i8* %52)
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%56 = sub i64 0, %55
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = call i64 @gms_strcasecmp(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %70, label %60
60: ; preds = %50
%61 = load i8*, i8** %9
%62 = load i8*, i8** %9
%63 = call i64 @strlen(i8* %62)
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%66 = sub i64 0, %65
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = call i64 @gms_strcasecmp(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %77
70: ; preds = %60, %50, %40
%71 = load i8*, i8** %9
%72 = load i8*, i8** %9
%73 = call i64 @strlen(i8* %72)
%74 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%75 = sub i64 %73, %74
%76 = getelementptr inbounds i8, i8* %71, i64 %75
store i8 0, i8* %76
br label %77
77: ; preds = %70, %60
br label %78
78: ; preds = %77, %25
%79 = load i8*, i8** %9
%80 = call i64 @strlen(i8* %79)
%81 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%82 = add i64 %80, %81
%83 = add i64 %82, 1
%84 = call i8* @gms_malloc(i64 %83)
store i8* %84, i8** %10
%85 = load i8*, i8** %10
%86 = load i8*, i8** %9
%87 = call i32 @strcpy(i8* %85, i8* %86)
%88 = load i8*, i8** %10
%89 = call i32 @strcat(i8* %88, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%90 = load i8*, i8** %10
%91 = call i32* @fopen(i8* %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %91, i32** %13
%92 = load i32*, i32** %13
%93 = icmp ne i32* %92, null
br i1 %93, label %113, label %94
94: ; preds = %78
%95 = load i8*, i8** %10
%96 = load i8*, i8** %9
%97 = call i32 @strcpy(i8* %95, i8* %96)
%98 = load i8*, i8** %10
%99 = call i32 @strcat(i8* %98, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%100 = load i8*, i8** %10
%101 = call i32* @fopen(i8* %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %101, i32** %13
%102 = load i32*, i32** %13
%103 = icmp ne i32* %102, null
br i1 %103, label %112, label %104
104: ; preds = %94
%105 = load i8**, i8*** %6
store i8* null, i8** %105
%106 = load i8**, i8*** %7
store i8* null, i8** %106
%107 = load i8**, i8*** %8
store i8* null, i8** %107
%108 = load i8*, i8** %10
%109 = call i32 @free(i8* %108)
%110 = load i8*, i8** %9
%111 = call i32 @free(i8* %110)
br label %200
112: ; preds = %94
br label %113
113: ; preds = %112, %78
%114 = load i32*, i32** %13
%115 = icmp ne i32* %114, null
br i1 %115, label %116, label %119
116: ; preds = %113
%117 = load i32*, i32** %13
%118 = call i32 @fclose(i32* %117)
br label %119
119: ; preds = %116, %113
%120 = load i8*, i8** %9
%121 = call i64 @strlen(i8* %120)
%122 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%123 = add i64 %121, %122
%124 = add i64 %123, 1
%125 = call i8* @gms_malloc(i64 %124)
store i8* %125, i8** %11
%126 = load i8*, i8** %11
%127 = load i8*, i8** %9
%128 = call i32 @strcpy(i8* %126, i8* %127)
%129 = load i8*, i8** %11
%130 = call i32 @strcat(i8* %129, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%131 = load i8*, i8** %11
%132 = call i32* @fopen(i8* %131, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %132, i32** %13
%133 = load i32*, i32** %13
%134 = icmp ne i32* %133, null
br i1 %134, label %149, label %135
135: ; preds = %119
%136 = load i8*, i8** %11
%137 = load i8*, i8** %9
%138 = call i32 @strcpy(i8* %136, i8* %137)
%139 = load i8*, i8** %11
%140 = call i32 @strcat(i8* %139, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%141 = load i8*, i8** %11
%142 = call i32* @fopen(i8* %141, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %142, i32** %13
%143 = load i32*, i32** %13
%144 = icmp ne i32* %143, null
br i1 %144, label %148, label %145
145: ; preds = %135
%146 = load i8*, i8** %11
%147 = call i32 @free(i8* %146)
store i8* null, i8** %11
br label %148
148: ; preds = %145, %135
br label %149
149: ; preds = %148, %119
%150 = load i32*, i32** %13
%151 = icmp ne i32* %150, null
br i1 %151, label %152, label %155
152: ; preds = %149
%153 = load i32*, i32** %13
%154 = call i32 @fclose(i32* %153)
br label %155
155: ; preds = %152, %149
%156 = load i8*, i8** %9
%157 = call i64 @strlen(i8* %156)
%158 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%159 = add i64 %157, %158
%160 = add i64 %159, 1
%161 = call i8* @gms_malloc(i64 %160)
store i8* %161, i8** %12
%162 = load i8*, i8** %12
%163 = load i8*, i8** %9
%164 = call i32 @strcpy(i8* %162, i8* %163)
%165 = load i8*, i8** %12
%166 = call i32 @strcat(i8* %165, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%167 = load i8*, i8** %12
%168 = call i32* @fopen(i8* %167, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %168, i32** %13
%169 = load i32*, i32** %13
%170 = icmp ne i32* %169, null
br i1 %170, label %185, label %171
171: ; preds = %155
%172 = load i8*, i8** %12
%173 = load i8*, i8** %9
%174 = call i32 @strcpy(i8* %172, i8* %173)
%175 = load i8*, i8** %12
%176 = call i32 @strcat(i8* %175, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%177 = load i8*, i8** %12
%178 = call i32* @fopen(i8* %177, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %178, i32** %13
%179 = load i32*, i32** %13
%180 = icmp ne i32* %179, null
br i1 %180, label %184, label %181
181: ; preds = %171
%182 = load i8*, i8** %12
%183 = call i32 @free(i8* %182)
store i8* null, i8** %12
br label %184
184: ; preds = %181, %171
br label %185
185: ; preds = %184, %155
%186 = load i32*, i32** %13
%187 = icmp ne i32* %186, null
br i1 %187, label %188, label %191
188: ; preds = %185
%189 = load i32*, i32** %13
%190 = call i32 @fclose(i32* %189)
br label %191
191: ; preds = %188, %185
%192 = load i8*, i8** %10
%193 = load i8**, i8*** %6
store i8* %192, i8** %193
%194 = load i8*, i8** %11
%195 = load i8**, i8*** %7
store i8* %194, i8** %195
%196 = load i8*, i8** %12
%197 = load i8**, i8*** %8
store i8* %196, i8** %197
%198 = load i8*, i8** %9
%199 = call i32 @free(i8* %198)
br label %200
200: ; preds = %191, %104
ret void
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c".MAG\00"
@.str.2 = [5 x i8] c".GFX\00"
@.str.3 = [5 x i8] c".HNT\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [5 x i8] c".mag\00"
@.str.6 = [5 x i8] c".gfx\00"
@.str.7 = [5 x i8] c".hnt\00"
define void @gms_establish_filenames(i8* %0, i8** writeonly %1, i8** writeonly %2, i8** writeonly %3) {
%5 = icmp ne i8* %0, null
%6 = icmp ne i8** %1, null
%7 = and i1 %5, %6
%8 = icmp ne i8** %2, null
%9 = and i1 %7, %8
%10 = icmp ne i8** %3, null
%11 = and i1 %9, %10
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%15 = add i64 %14, 1
%16 = tail call i8* @gms_malloc(i64 %15)
%17 = tail call i32 @strcpy(i8* %16, i8* %0)
%18 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%19 = icmp ugt i64 %18, 4
br i1 %19, label %20, label %41
20: ; preds = %4
%21 = getelementptr inbounds i8, i8* %16, i64 %18
%22 = getelementptr inbounds i8, i8* %21, i64 -4
%23 = tail call i64 @gms_strcasecmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %37, label %25
25: ; preds = %20
%26 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%27 = getelementptr inbounds i8, i8* %16, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 -4
%29 = tail call i64 @gms_strcasecmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %25
%32 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%33 = getelementptr inbounds i8, i8* %16, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 -4
%35 = tail call i64 @gms_strcasecmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %31, %25, %20
%38 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%39 = add i64 %38, -4
%40 = getelementptr inbounds i8, i8* %16, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %31, %37, %4
%42 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%43 = add i64 %42, 5
%44 = tail call i8* @gms_malloc(i64 %43)
%45 = tail call i32 @strcpy(i8* %44, i8* %16)
%46 = tail call i32 @strcat(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%47 = tail call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %56
49: ; preds = %41
%50 = tail call i32 @strcpy(i8* %44, i8* %16)
%51 = tail call i32 @strcat(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%52 = tail call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %56
54: ; preds = %49
store i8* null, i8** %1
store i8* null, i8** %2
store i8* null, i8** %3
%55 = tail call i32 @free(i8* %44)
br label %97
56: ; preds = %49, %41
%57 = phi i32* [ %47, %41 ], [ %52, %49 ]
%58 = tail call i32 @fclose(i32* %57)
%59 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%60 = add i64 %59, 5
%61 = tail call i8* @gms_malloc(i64 %60)
%62 = tail call i32 @strcpy(i8* %61, i8* %16)
%63 = tail call i32 @strcat(i8* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%64 = tail call i32* @fopen(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%65 = icmp eq i32* %64, null
br i1 %65, label %66, label %73
66: ; preds = %56
%67 = tail call i32 @strcpy(i8* %61, i8* %16)
%68 = tail call i32 @strcat(i8* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%69 = tail call i32* @fopen(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%70 = icmp eq i32* %69, null
br i1 %70, label %71, label %73
71: ; preds = %66
%72 = tail call i32 @free(i8* %61)
br label %76
73: ; preds = %56, %66
%74 = phi i32* [ %69, %66 ], [ %64, %56 ]
%75 = tail call i32 @fclose(i32* %74)
br label %76
76: ; preds = %71, %73
%77 = phi i8* [ %61, %73 ], [ null, %71 ]
%78 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%79 = add i64 %78, 5
%80 = tail call i8* @gms_malloc(i64 %79)
%81 = tail call i32 @strcpy(i8* %80, i8* %16)
%82 = tail call i32 @strcat(i8* %80, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%83 = tail call i32* @fopen(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%84 = icmp eq i32* %83, null
br i1 %84, label %85, label %92
85: ; preds = %76
%86 = tail call i32 @strcpy(i8* %80, i8* %16)
%87 = tail call i32 @strcat(i8* %80, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%88 = tail call i32* @fopen(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%89 = icmp eq i32* %88, null
br i1 %89, label %90, label %92
90: ; preds = %85
%91 = tail call i32 @free(i8* %80)
br label %95
92: ; preds = %76, %85
%93 = phi i32* [ %88, %85 ], [ %83, %76 ]
%94 = tail call i32 @fclose(i32* %93)
br label %95
95: ; preds = %90, %92
%96 = phi i8* [ %80, %92 ], [ null, %90 ]
store i8* %44, i8** %1
store i8* %77, i8** %2
store i8* %96, i8** %3
br label %97
97: ; preds = %95, %54
%98 = tail call i32 @free(i8* %16)
ret void
}