#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 */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int, int);
scalar_t__ write(int, char *, int);
int global_fd_log(void) {
  static int fd = -2;
  if (fd == -2)
    if ((fd = open("./log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0755)) == -1 &&
        write(2,
              "\033[33m"
              "log could not be oppened or created\n"
              "\033[0m",
              46))
      exit(-1);
  return (fd);
}


x86 assembly (clang, -O0):
<global_fd_log>:
push   %rbp
mov    %rsp,%rbp
cmpl   $0xfffffffe,0x2efd(%rip)
jne    11ab <global_fd_log+0x7b>
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    0x2ea7(%rip),%rax
or     (%rax),%esi
mov    0x2e96(%rip),%rax
or     (%rax),%esi
lea    0xe9d(%rip),%rdi
mov    $0x1ed,%edx
call   1040 <open@plt>
mov    %eax,0x2ec5(%rip)
cmp    $0xffffffff,%eax
jne    11a6 <global_fd_log+0x76>
mov    $0x2,%edi
lea    0xe82(%rip),%rsi
mov    $0x2e,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
je     11a6 <global_fd_log+0x76>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
jmp    11ab <global_fd_log+0x7b>
mov    0x2e87(%rip),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<global_fd_log>:
push   %rax
mov    0x2f01(%rip),%eax
cmp    $0xfffffffe,%eax
jne    1173 <global_fd_log+0x43>
mov    0x2e85(%rip),%rax
mov    0x2eae(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e9b(%rip),%rax
or     (%rax),%esi
lea    0xea2(%rip),%rdi
mov    $0x1ed,%edx
call   1040 <open@plt>
mov    %eax,0x2eca(%rip)
cmp    $0xffffffff,%eax
je     1175 <global_fd_log+0x45>
pop    %rcx
ret
lea    0xe8e(%rip),%rsi
mov    $0x2,%edi
mov    $0x2e,%edx
call   1030 <write@plt>
test   %rax,%rax
jne    1198 <global_fd_log+0x68>
mov    0x2ea2(%rip),%eax
pop    %rcx
ret
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@global_fd_log.fd = internal global i32 -2
@.str = [10 x i8] c"./log.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [46 x i8] c"\1B[33mlog could not be oppened or created\0A\1B[0m\00"
define i32 @global_fd_log() {
%1 = load i32, i32* @global_fd_log.fd
%2 = icmp eq i32 %1, -2
br i1 %2, label %3, label %17
3: ; preds = %0
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %4, %5
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i32 493)
store i32 %9, i32* @global_fd_log.fd
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = call i64 @write(i32 2, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 46)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %11, %3
br label %17
17: ; preds = %16, %0
%18 = load i32, i32* @global_fd_log.fd
ret i32 %18
}

LLVM IR (-O2):
@global_fd_log.fd = internal unnamed_addr global i32 -2
@.str = [10 x i8] c"./log.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [46 x i8] c"\1B[33mlog could not be oppened or created\0A\1B[0m\00"
define i32 @global_fd_log() {
%1 = load i32, i32* @global_fd_log.fd
%2 = icmp eq i32 %1, -2
br i1 %2, label %3, label %18
3: ; preds = %0
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i32 493)
store i32 %9, i32* @global_fd_log.fd
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %18
11: ; preds = %3
%12 = tail call i64 @write(i32 2, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 46)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = load i32, i32* @global_fd_log.fd
br label %18
16: ; preds = %11
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %14, %3, %0
%19 = phi i32 [ %15, %14 ], [ %9, %3 ], [ %1, %0 ]
ret i32 %19
}