#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*/ *fopen(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ setlinebuf(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
__attribute__((visibility("internal"))) FILE *__my_getlog() {
  static FILE *file = NULL;
  if (!file) {
    char *name = getenv("RESOLVE_LOG_FILE");
    if (!name) {
      file = stderr;
    } else {
      file = fopen(name, "a");
      setlinebuf(file);
    }
  }
  return file;
}


x86 assembly (clang, -O0):
<__my_getlog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpq   $0x0,0x2f00(%rip)
jne    119f <__my_getlog+0x6f>
lea    0xeb3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1177 <__my_getlog+0x47>
mov    0x2e78(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x2ece(%rip)
jmp    119a <__my_getlog+0x6a>
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,0x2eb2(%rip)
mov    0x2eab(%rip),%rdi
call   1040 <setlinebuf@plt>
jmp    119f <__my_getlog+0x6f>
mov    0x2e9a(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__my_getlog>:
push   %rax
mov    0x2f08(%rip),%rax
test   %rax,%rax
je     113f <__my_getlog+0xf>
pop    %rcx
ret
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1177 <__my_getlog+0x47>
lea    0xeba(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
mov    %rax,0x2eda(%rip)
mov    %rax,%rdi
call   1040 <setlinebuf@plt>
mov    0x2ecb(%rip),%rax
pop    %rcx
ret
mov    0x2e62(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x2eb8(%rip)
pop    %rcx
ret

LLVM IR (-O0):
@__my_getlog.file = internal global i32* null
@.str = [17 x i8] c"RESOLVE_LOG_FILE\00"
@stderr = global i32* null
@.str.1 = [2 x i8] c"a\00"
define hidden i32* @__my_getlog() {
%1 = alloca i8*
%2 = load i32*, i32** @__my_getlog.file
%3 = icmp ne i32* %2, null
br i1 %3, label %16, label %4
4: ; preds = %0
%5 = call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = icmp ne i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = load i32*, i32** @stderr
store i32* %9, i32** @__my_getlog.file
br label %15
10: ; preds = %4
%11 = load i8*, i8** %1
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** @__my_getlog.file
%13 = load i32*, i32** @__my_getlog.file
%14 = call i32 @setlinebuf(i32* %13)
br label %15
15: ; preds = %10, %8
br label %16
16: ; preds = %15, %0
%17 = load i32*, i32** @__my_getlog.file
ret i32* %17
}

LLVM IR (-O2):
@__my_getlog.file = internal unnamed_addr global i32* null
@.str = [17 x i8] c"RESOLVE_LOG_FILE\00"
@stderr = global i32* null
@.str.1 = [2 x i8] c"a\00"
define hidden i32* @__my_getlog() {
%1 = load i32*, i32** @__my_getlog.file
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = load i32*, i32** @stderr
store i32* %7, i32** @__my_getlog.file
br label %12
8: ; preds = %3
%9 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** @__my_getlog.file
%10 = tail call i32 @setlinebuf(i32* %9)
%11 = load i32*, i32** @__my_getlog.file
br label %12
12: ; preds = %6, %8, %0
%13 = phi i32* [ %7, %6 ], [ %11, %8 ], [ %1, %0 ]
ret i32* %13
}