#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int errno;
int lstat(char const *, struct stat *);
char *realpath(char const *, int /*<<< orphan*/ *);
char *config_realpath(const char *path, int symlinks) {
  const char *tmppath = (path != NULL) ? path : ".";
  int storerr = errno;
  struct stat buf;
  char *rp;
  if (lstat(tmppath, &buf) == -1) {
    return NULL;
  }
  if (symlinks == 0 && S_ISLNK(buf.st_mode)) {
    return NULL;
  }
  errno = 0;
  rp = realpath(tmppath, NULL);
  if (errno == 0) {
    errno = storerr;
  }
  return rp;
}


x86 assembly (clang, -O0):
<config_realpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1157 <config_realpath+0x27>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1167 <config_realpath+0x37>
lea    0xea2(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    1167 <config_realpath+0x37>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
jne    119e <config_realpath+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    1209 <config_realpath+0xd9>
cmpl   $0x0,-0x14(%rbp)
jne    11c7 <config_realpath+0x97>
mov    -0x28(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     11c7 <config_realpath+0x97>
movq   $0x0,-0x8(%rbp)
jmp    1209 <config_realpath+0xd9>
mov    0x2e12(%rip),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <realpath@plt>
mov    %rax,-0x30(%rbp)
mov    0x2df4(%rip),%rax
cmpl   $0x0,(%rax)
jne    1201 <config_realpath+0xd1>
mov    -0x24(%rbp),%ecx
mov    0x2de1(%rip),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_realpath>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
test   %rdi,%rdi
lea    0xebd(%rip),%rbx
cmovne %rdi,%rbx
mov    0x2e92(%rip),%r14
mov    (%r14),%r15d
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
je     118e <config_realpath+0x5e>
test   %ebp,%ebp
je     1181 <config_realpath+0x51>
movl   $0x0,(%r14)
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <realpath@plt>
cmpl   $0x0,(%r14)
jne    1190 <config_realpath+0x60>
mov    %r15d,(%r14)
jmp    1190 <config_realpath+0x60>
mov    (%rsp),%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
je     1165 <config_realpath+0x35>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c".\00"
@errno = global i32 0
define i8* @config_realpath(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i8*, i8** %4
br label %15
14: ; preds = %2
br label %15
15: ; preds = %14, %12
%16 = phi i8* [ %13, %12 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %14 ]
store i8* %16, i8** %6
%17 = load i32, i32* @errno
store i32 %17, i32* %7
%18 = load i8*, i8** %6
%19 = call i32 @lstat(i8* %18, %struct.stat* %8)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %15
store i8* null, i8** %3
br label %40
22: ; preds = %15
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i64 @S_ISLNK(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i8* null, i8** %3
br label %40
31: ; preds = %25, %22
store i32 0, i32* @errno
%32 = load i8*, i8** %6
%33 = call i8* @realpath(i8* %32, i32* null)
store i8* %33, i8** %9
%34 = load i32, i32* @errno
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = load i32, i32* %7
store i32 %37, i32* @errno
br label %38
38: ; preds = %36, %31
%39 = load i8*, i8** %9
store i8* %39, i8** %3
br label %40
40: ; preds = %38, %30, %21
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c".\00"
@errno = global i32 0
define i8* @config_realpath(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = icmp eq i8* %0, null
%5 = select i1 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0
%6 = load i32, i32* @errno
%7 = bitcast %struct.stat* %3 to i8*
%8 = call i32 @lstat(i8* %5, %struct.stat* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %22, label %10
10: ; preds = %2
%11 = icmp eq i32 %1, 0
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = tail call i64 @S_ISLNK(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12, %10
store i32 0, i32* @errno
%18 = tail call i8* @realpath(i8* %5, i32* null)
%19 = load i32, i32* @errno
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 %6, i32* @errno
br label %22
22: ; preds = %17, %21, %12, %2
%23 = phi i8* [ null, %2 ], [ null, %12 ], [ %18, %21 ], [ %18, %17 ]
ret i8* %23
}