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

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, char *, ...);
char *strerror(int);
void pr_stat(const char *path, struct stat *s, int errcode) {
  if (errcode != 0) {
    printf("stat_a: %s: error: %s\n", path, strerror(errcode));
  } else {
    printf("stat_a: %s: type = %s, size = %u\n", path,
           S_ISDIR(s->st_mode)   ? "dir"
           : S_ISREG(s->st_mode) ? "file"
                                 : "?",
           (unsigned)s->st_size);
  }
}


x86 assembly (clang, -O0):
<pr_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1187 <pr_stat+0x47>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fd <pr_stat+0xbd>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11b5 <pr_stat+0x75>
lea    0xe8d(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11de <pr_stat+0x9e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rdx
lea    0xe77(%rip),%rax
lea    0xe6b(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%ecx
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_stat>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %edx,%edx
je     116d <pr_stat+0x2d>
mov    %edx,%edi
call   1060 <strerror@plt>
lea    0xea7(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>
mov    %rsi,%rbx
mov    0x8(%rsi),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     1186 <pr_stat+0x46>
lea    0xeb5(%rip),%rdx
jmp    11a3 <pr_stat+0x63>
mov    0x8(%rbx),%edi
call   1050 <S_ISREG@plt>
test   %rax,%rax
lea    0xeaa(%rip),%rax
lea    0xe9e(%rip),%rdx
cmove  %rax,%rdx
mov    (%rbx),%ecx
lea    0xe6b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
@.str = [23 x i8] c"stat_a: %s: error: %s\0A\00"
@.str.1 = [34 x i8] c"stat_a: %s: type = %s, size = %u\0A\00"
@.str.2 = [4 x i8] c"dir\00"
@.str.3 = [5 x i8] c"file\00"
@.str.4 = [2 x i8] c"?\00"
define void @pr_stat(i8* %0, %struct.stat* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca %struct.stat*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.stat* %1, %struct.stat** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i8*, i8** %4
%11 = load i32, i32* %6
%12 = call i8* @strerror(i32 %11)
%13 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %12)
br label %37
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = load %struct.stat*, %struct.stat** %5
%17 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %30
22: ; preds = %14
%23 = load %struct.stat*, %struct.stat** %5
%24 = getelementptr inbounds %struct.stat, %struct.stat* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = call i64 @S_ISREG(i32 %25)
%27 = icmp ne i64 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
br label %30
30: ; preds = %22, %21
%31 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %21 ], [ %29, %22 ]
%32 = load %struct.stat*, %struct.stat** %5
%33 = getelementptr inbounds %struct.stat, %struct.stat* %32, i32 0, i32 0
%34 = load i64, i64* %33
%35 = trunc i64 %34 to i32
%36 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %31, i32 %35)
br label %37
37: ; preds = %30, %9
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
@.str = [23 x i8] c"stat_a: %s: error: %s\0A\00"
@.str.1 = [34 x i8] c"stat_a: %s: type = %s, size = %u\0A\00"
@.str.2 = [4 x i8] c"dir\00"
@.str.3 = [5 x i8] c"file\00"
@.str.4 = [2 x i8] c"?\00"
define void @pr_stat(i8* %0, %struct.stat* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %8, label %5
5: ; preds = %3
%6 = tail call i8* @strerror(i32 %2)
%7 = tail call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %6)
br label %24
8: ; preds = %3
%9 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = tail call i64 @S_ISDIR(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* %9
%15 = tail call i64 @S_ISREG(i32 %14)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
br label %18
18: ; preds = %8, %13
%19 = phi i8* [ %17, %13 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %8 ]
%20 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%21 = load i64, i64* %20
%22 = trunc i64 %21 to i32
%23 = tail call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %19, i32 %22)
br label %24
24: ; preds = %18, %5
ret void
}