#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 const *get_default_magic();
char *getenv(char *);
const char *magic_getpath(const char *magicfile, int action) {
  if (magicfile != NULL)
    return magicfile;
  magicfile = getenv("MAGIC");
  if (magicfile != NULL)
    return magicfile;
  return action == 0 ? get_default_magic() : "/etc/magic";
}


x86 assembly (clang, -O0):
<magic_getpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1147 <magic_getpath+0x27>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a1 <magic_getpath+0x81>
lea    0xeb2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116f <magic_getpath+0x4f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a1 <magic_getpath+0x81>
cmpl   $0x0,-0x14(%rbp)
jne    1189 <magic_getpath+0x69>
mov    $0x0,%al
call   1040 <get_default_magic@plt>
mov    %rax,-0x20(%rbp)
jmp    1199 <magic_getpath+0x79>
lea    0xe76(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1199 <magic_getpath+0x79>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<magic_getpath>:
push   %rbx
mov    %rdi,%rax
test   %rdi,%rdi
je     112b <magic_getpath+0xb>
pop    %rbx
ret
mov    %esi,%ebx
lea    0xecc(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1129 <magic_getpath+0x9>
test   %ebx,%ebx
je     114b <magic_getpath+0x2b>
lea    0xebd(%rip),%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
jmp    1040 <get_default_magic@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"MAGIC\00"
@.str.1 = [11 x i8] c"/etc/magic\00"
define i8* @magic_getpath(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i8*, i8** %4
store i8* %9, i8** %3
br label %24
10: ; preds = %2
%11 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = load i8*, i8** %4
store i8* %15, i8** %3
br label %24
16: ; preds = %10
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i8* (...) @get_default_magic()
br label %22
21: ; preds = %16
br label %22
22: ; preds = %21, %19
%23 = phi i8* [ %20, %19 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %21 ]
store i8* %23, i8** %3
br label %24
24: ; preds = %22, %14, %8
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@.str = [6 x i8] c"MAGIC\00"
@.str.1 = [11 x i8] c"/etc/magic\00"
define i8* @magic_getpath(i8* readnone %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = icmp eq i32 %1, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i8* (...) @get_default_magic()
br label %11
11: ; preds = %9, %7, %4, %2
%12 = phi i8* [ %0, %2 ], [ %5, %4 ], [ %10, %9 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %7 ]
ret i8* %12
}