#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AT_SYMLINK_NOFOLLOW;
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ fstatat(int, char *, struct stat *, int /*<<< orphan*/);
int myls_get_file_stat(int dir, char *filename, struct stat **stat) {
  struct stat *filename_stat = *stat;
  if (fstatat(dir, filename, filename_stat, AT_SYMLINK_NOFOLLOW))
    return EXIT_FAILURE;
  *stat = filename_stat;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<myls_get_file_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    0x2e98(%rip),%rax
mov    (%rax),%ecx
call   1030 <fstatat@plt>
cmp    $0x0,%rax
je     1162 <myls_get_file_stat+0x52>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1179 <myls_get_file_stat+0x69>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myls_get_file_stat>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    (%rdx),%rbx
mov    0x2eb7(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdx
call   1030 <fstatat@plt>
test   %rax,%rax
je     1139 <myls_get_file_stat+0x29>
mov    0x2ea9(%rip),%rax
jmp    1143 <myls_get_file_stat+0x33>
mov    %rbx,(%r14)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@AT_SYMLINK_NOFOLLOW = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @myls_get_file_stat(i32 %0, i8* %1, %struct.stat** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.stat**
%8 = alloca %struct.stat*
store i32 %0, i32* %5
store i8* %1, i8** %6
store %struct.stat** %2, %struct.stat*** %7
%9 = load %struct.stat**, %struct.stat*** %7
%10 = load %struct.stat*, %struct.stat** %9
store %struct.stat* %10, %struct.stat** %8
%11 = load i32, i32* %5
%12 = load i8*, i8** %6
%13 = load %struct.stat*, %struct.stat** %8
%14 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%15 = call i64 @fstatat(i32 %11, i8* %12, %struct.stat* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %4
br label %23
19: ; preds = %3
%20 = load %struct.stat*, %struct.stat** %8
%21 = load %struct.stat**, %struct.stat*** %7
store %struct.stat* %20, %struct.stat** %21
%22 = load i32, i32* @EXIT_SUCCESS
store i32 %22, i32* %4
br label %23
23: ; preds = %19, %17
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@AT_SYMLINK_NOFOLLOW = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @myls_get_file_stat(i32 %0, i8* %1, %struct.stat** nocapture %2) {
%4 = load %struct.stat*, %struct.stat** %2
%5 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%6 = tail call i64 @fstatat(i32 %0, i8* %1, %struct.stat* %4, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %3
store %struct.stat* %4, %struct.stat** %2
br label %9
9: ; preds = %3, %8
%10 = phi i32* [ @EXIT_SUCCESS, %8 ], [ @EXIT_FAILURE, %3 ]
%11 = load i32, i32* %10
ret i32 %11
}