#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*/ fullname;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ *fopen(char const *, char *);
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
FILE *zconf_fopen(const char *name) {
  char *env, fullname[PATH_MAX + 1];
  FILE *f;
  f = fopen(name, "r");
  if (!f && name != NULL && name[0] != '/') {
    env = getenv("srctree");
    if (env) {
      snprintf(fullname, sizeof(fullname), "%s/%s", env, name);
      f = fopen(fullname, "r");
    }
  }
  return f;
}


x86 assembly (clang, -O0):
<zconf_fopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11fb <zconf_fopen+0xcb>
cmpq   $0x0,-0x8(%rbp)
je     11fb <zconf_fopen+0xcb>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11fb <zconf_fopen+0xcb>
lea    0xe52(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f6 <zconf_fopen+0xc6>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe2d(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    11fb <zconf_fopen+0xcb>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zconf_fopen>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eac(%rip),%rax
mov    (%rax),%r15d
add    $0x1,%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe9d(%rip),%rsi
call   1050 <fopen@plt>
test   %r14,%r14
je     11b4 <zconf_fopen+0x84>
test   %rax,%rax
jne    11b4 <zconf_fopen+0x84>
cmpb   $0x2f,(%r14)
je     11b2 <zconf_fopen+0x82>
lea    0xe83(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b2 <zconf_fopen+0x82>
lea    0xe7a(%rip),%rdx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %rax,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
jmp    11b4 <zconf_fopen+0x84>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"srctree\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32* @zconf_fopen(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
store i8* %0, i8** %2
%7 = load i32, i32* @PATH_MAX
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
%12 = load i8*, i8** %2
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %36, label %16
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %36
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 47
br i1 %24, label %25, label %36
25: ; preds = %19
%26 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = trunc i64 %9 to i32
%31 = load i8*, i8** %3
%32 = load i8*, i8** %2
%33 = call i32 @snprintf(i8* %11, i32 %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %32)
%34 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %34, i32** %6
br label %35
35: ; preds = %29, %25
br label %36
36: ; preds = %35, %19, %16, %1
%37 = load i32*, i32** %6
%38 = load i8*, i8** %4
ret i32* %37
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"srctree\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define noalias i32* @zconf_fopen(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
%8 = icmp ne i8* %0, null
%9 = and i1 %8, %7
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = load i8, i8* %0
%12 = icmp eq i8 %11, 47
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i32 @snprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %14, i8* %0)
%18 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %13, %16, %10, %1
%20 = phi i32* [ %18, %16 ], [ null, %13 ], [ null, %10 ], [ %6, %1 ]
ret i32* %20
}