#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*/ PATH_MAX;
int /*<<< orphan*/ *fopen(char const *, char *);
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, 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) {
      sprintf(fullname, "%s/%s", env, name);
      f = fopen(fullname, "r");
    }
  }
  return f;
}


x86 assembly (clang, -O0):
<zconf_fopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
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    0xe8a(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f1 <zconf_fopen+0xc1>
cmpq   $0x0,-0x8(%rbp)
je     11f1 <zconf_fopen+0xc1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11f1 <zconf_fopen+0xc1>
lea    0xe56(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ec <zconf_fopen+0xbc>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe37(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    11f1 <zconf_fopen+0xc1>
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   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2eaf(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xea2(%rip),%rsi
call   1040 <fopen@plt>
test   %r14,%r14
je     11ac <zconf_fopen+0x7c>
test   %rax,%rax
jne    11ac <zconf_fopen+0x7c>
cmpb   $0x2f,(%r14)
je     11aa <zconf_fopen+0x7a>
lea    0xe88(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11aa <zconf_fopen+0x7a>
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
mov    %r14,%rcx
call   1050 <sprintf@plt>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
jmp    11ac <zconf_fopen+0x7c>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
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 %35, label %16
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %35
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 %35
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 %34
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = load i8*, i8** %2
%32 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %30, i8* %31)
%33 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %33, i32** %6
br label %34
34: ; preds = %29, %25
br label %35
35: ; preds = %34, %19, %16, %1
%36 = load i32*, i32** %6
%37 = load i8*, i8** %4
ret i32* %36
}

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 @sprintf(i8* %5, i8* dereferenceable(1) 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
}