#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 */

/* Variables and functions */
char *getenv(char *);
scalar_t__ strcmp(char const *, char const *);
const char *sub_filename(const char *filename) {
  static const char *orig = NULL;
  static const char *sub = NULL;
  const char *result;
  if (orig == NULL) {
    orig = getenv("MUTATE_ORIG_SRC");
  }
  if (sub == NULL) {
    sub = getenv("MUTATE_MODIFIED_SRC");
  }
  if (orig != NULL && sub != NULL && strcmp(orig, filename) == 0) {
    result = sub;
  } else {
    result = filename;
  }
  return result;
}


x86 assembly (clang, -O0):
<sub_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,0x2f04(%rip)
jne    114d <sub_filename+0x2d>
lea    0xebf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2eeb(%rip)
cmpq   $0x0,0x2eeb(%rip)
jne    116e <sub_filename+0x4e>
lea    0xeae(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ed2(%rip)
cmpq   $0x0,0x2ec2(%rip)
je     11b4 <sub_filename+0x94>
cmpq   $0x0,0x2ebc(%rip)
je     11b4 <sub_filename+0x94>
mov    0x2ea7(%rip),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11b4 <sub_filename+0x94>
mov    0x2e95(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11bc <sub_filename+0x9c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sub_filename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2f0a(%rip),%rbx
test   %rbx,%rbx
jne    1149 <sub_filename+0x29>
lea    0xec6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %rax,0x2eef(%rip)
mov    0x2ef0(%rip),%rax
test   %rax,%rax
jne    1168 <sub_filename+0x48>
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ed8(%rip)
test   %rbx,%rbx
je     1189 <sub_filename+0x69>
test   %rax,%rax
je     1189 <sub_filename+0x69>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1189 <sub_filename+0x69>
mov    0x2eb7(%rip),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@sub_filename.orig = internal global i8* null
@sub_filename.sub = internal global i8* null
@.str = [16 x i8] c"MUTATE_ORIG_SRC\00"
@.str.1 = [20 x i8] c"MUTATE_MODIFIED_SRC\00"
define i8* @sub_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** @sub_filename.orig
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** @sub_filename.orig
br label %8
8: ; preds = %6, %1
%9 = load i8*, i8** @sub_filename.sub
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** @sub_filename.sub
br label %13
13: ; preds = %11, %8
%14 = load i8*, i8** @sub_filename.orig
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i8*, i8** @sub_filename.sub
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i8*, i8** @sub_filename.orig
%21 = load i8*, i8** %2
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = load i8*, i8** @sub_filename.sub
store i8* %25, i8** %3
br label %28
26: ; preds = %19, %16, %13
%27 = load i8*, i8** %2
store i8* %27, i8** %3
br label %28
28: ; preds = %26, %24
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@sub_filename.orig = internal unnamed_addr global i8* null
@sub_filename.sub = internal unnamed_addr global i8* null
@.str = [16 x i8] c"MUTATE_ORIG_SRC\00"
@.str.1 = [20 x i8] c"MUTATE_MODIFIED_SRC\00"
define i8* @sub_filename(i8* %0) {
%2 = load i8*, i8** @sub_filename.orig
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** @sub_filename.orig
br label %6
6: ; preds = %4, %1
%7 = phi i8* [ %5, %4 ], [ %2, %1 ]
%8 = load i8*, i8** @sub_filename.sub
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** @sub_filename.sub
br label %12
12: ; preds = %10, %6
%13 = phi i8* [ %11, %10 ], [ %8, %6 ]
%14 = icmp ne i8* %7, null
%15 = icmp ne i8* %13, null
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = tail call i64 @strcmp(i8* %7, i8* %0)
%19 = icmp eq i64 %18, 0
%20 = load i8*, i8** @sub_filename.sub
%21 = select i1 %19, i8* %20, i8* %0
br label %22
22: ; preds = %17, %12
%23 = phi i8* [ %0, %12 ], [ %21, %17 ]
ret i8* %23
}