#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_ISCHR(int /*<<< orphan*/);
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *);
int stat(char const *, struct stat *);
void findFileTypes(const char *pathname) {
  int ret = -1;
  struct stat buff;
  ret = stat(pathname, &buff);
  if (ret == -1)
    perror("stat() error");
  else {
    if (S_ISDIR(buff.st_mode))
      printf("%s is a directory.\n", pathname);
    else if (S_ISCHR(buff.st_mode))
      printf("%s is a character special file.\n", pathname);
    else if (S_ISREG(buff.st_mode))
      printf("%s is a regular file.\n", pathname);
    else
      printf("%s belongs to other file types.\n", pathname);
  }
}


x86 assembly (clang, -O0):
<findFileTypes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    119e <findFileTypes+0x3e>
lea    0xe6c(%rip),%rdi
call   1080 <perror@plt>
jmp    1232 <findFileTypes+0xd2>
mov    -0x10(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11c5 <findFileTypes+0x65>
mov    -0x8(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
jmp    122d <findFileTypes+0xcd>
mov    -0x10(%rbp),%edi
call   1070 <S_ISCHR@plt>
cmp    $0x0,%rax
je     11ec <findFileTypes+0x8c>
mov    -0x8(%rbp),%rsi
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
jmp    1228 <findFileTypes+0xc8>
mov    -0x10(%rbp),%edi
call   1060 <S_ISREG@plt>
cmp    $0x0,%rax
je     1213 <findFileTypes+0xb3>
mov    -0x8(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
jmp    1223 <findFileTypes+0xc3>
mov    -0x8(%rbp),%rsi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
jmp    1228 <findFileTypes+0xc8>
jmp    122d <findFileTypes+0xcd>
jmp    1232 <findFileTypes+0xd2>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findFileTypes>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     11b5 <findFileTypes+0x55>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     118b <findFileTypes+0x2b>
lea    0xe84(%rip),%rdi
jmp    11ce <findFileTypes+0x6e>
mov    %ebp,%edi
call   1070 <S_ISCHR@plt>
test   %rax,%rax
je     11a0 <findFileTypes+0x40>
lea    0xe83(%rip),%rdi
jmp    11ce <findFileTypes+0x6e>
mov    %ebp,%edi
call   1060 <S_ISREG@plt>
test   %rax,%rax
je     11c7 <findFileTypes+0x67>
lea    0xe8f(%rip),%rdi
jmp    11ce <findFileTypes+0x6e>
lea    0xe44(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1080 <perror@plt>
lea    0xe8b(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [13 x i8] c"stat() error\00"
@.str.1 = [20 x i8] c"%s is a directory.\0A\00"
@.str.2 = [33 x i8] c"%s is a character special file.\0A\00"
@.str.3 = [23 x i8] c"%s is a regular file.\0A\00"
@.str.4 = [33 x i8] c"%s belongs to other file types.\0A\00"
define void @findFileTypes(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.stat
store i8* %0, i8** %2
store i32 -1, i32* %3
%5 = load i8*, i8** %2
%6 = call i32 @stat(i8* %5, %struct.stat* %4)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %41
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i64 @S_ISDIR(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %40
19: ; preds = %11
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i64 @S_ISCHR(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i8*, i8** %2
%26 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %39
27: ; preds = %19
%28 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i64 @S_ISREG(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %2
%34 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %38
35: ; preds = %27
%36 = load i8*, i8** %2
%37 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %32
br label %39
39: ; preds = %38, %24
br label %40
40: ; preds = %39, %16
br label %41
41: ; preds = %40, %9
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [13 x i8] c"stat() error\00"
@.str.1 = [20 x i8] c"%s is a directory.\0A\00"
@.str.2 = [33 x i8] c"%s is a character special file.\0A\00"
@.str.3 = [23 x i8] c"%s is a regular file.\0A\00"
@.str.4 = [33 x i8] c"%s belongs to other file types.\0A\00"
define void @findFileTypes(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 %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %27
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i64 @S_ISDIR(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %27
15: ; preds = %8
%16 = tail call i64 @S_ISCHR(i32 %10)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %27
20: ; preds = %15
%21 = tail call i64 @S_ISREG(i32 %10)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %27
25: ; preds = %20
%26 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %27
27: ; preds = %13, %23, %25, %18, %6
ret void
}