#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ show_file_info(char *, struct stat *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void do_stat(char *fname) {
  struct stat info;
  if (stat(fname, &info) == -1)
    fprintf(stderr, "stat(%s) failed: %s\n", fname, strerror(errno));
  else
    show_file_info(fname, &info);
}


x86 assembly (clang, -O0):
<do_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    119f <do_stat+0x5f>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe6b(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11ac <do_stat+0x6c>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <show_file_info@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_stat>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     1165 <do_stat+0x25>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <show_file_info@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e74(%rip),%rax
mov    (%rax),%ebp
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe7d(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"stat(%s) failed: %s\0A\00"
@errno = global i32 0
define void @do_stat(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @stat(i8* %4, %struct.stat* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %2
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %11)
br label %16
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = call i32 @show_file_info(i8* %14, %struct.stat* %3)
br label %16
16: ; preds = %13, %7
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"stat(%s) failed: %s\0A\00"
@errno = global i32 0
define void @do_stat(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %9)
br label %13
11: ; preds = %1
%12 = call i32 @show_file_info(i8* %0, %struct.stat* %2)
br label %13
13: ; preds = %11, %6
ret void
}