#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ lstat(char *, struct stat *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
struct stat getstats(char *path) {
  struct stat stats;
  if (stat(path, &stats) || lstat(path, &stats)) {
    fprintf(stderr, "failed to get stats for: %s\n", path);
    exit(1);
  }
  return stats;
}


x86 assembly (clang, -O0):
<getstats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    117a <getstats+0x3a>
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <lstat@plt>
cmp    $0x0,%rax
je     119d <getstats+0x5d>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe72(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstats>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
jne    1173 <getstats+0x33>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <lstat@plt>
test   %rax,%rax
jne    1173 <getstats+0x33>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"failed to get stats for: %s\0A\00"
define i32 @getstats(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i64 @stat(i8* %4, %struct.stat* %2)
%6 = icmp ne i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i64 @lstat(i8* %8, %struct.stat* %2)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7, %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %7
%17 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%18 = load i32, i32* %17
ret i32 %18
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"failed to get stats for: %s\0A\00"
define i32 @getstats(i8* %0) {
%2 = alloca %struct.stat
%3 = call i64 @stat(i8* %0, %struct.stat* %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = call i64 @lstat(i8* %0, %struct.stat* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5, %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %5
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%14 = load i32, i32* %13
ret i32 %14
}