#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_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
int f_type(const char *filename) {
  static struct stat st;
  if (stat(filename, &st) != 0) {
    return -1;
  }
  if (S_ISREG(st.st_mode)) {
    return 0;
  } else if (S_ISDIR(st.st_mode)) {
    return 1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<f_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0x2ef5(%rip),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1162 <f_type+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <f_type+0x80>
mov    0x2ed4(%rip),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     1183 <f_type+0x53>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <f_type+0x80>
mov    0x2eb3(%rip),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11a4 <f_type+0x74>
movl   $0x1,-0x4(%rbp)
jmp    11b0 <f_type+0x80>
jmp    11a9 <f_type+0x79>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_type>:
push   %rax
lea    0x2f04(%rip),%rsi
call   1040 <stat@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     114c <f_type+0x1c>
pop    %rcx
ret
mov    0x2eea(%rip),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    114a <f_type+0x1a>
mov    0x2ed5(%rip),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
or     $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@f_type.st = internal global %struct.stat zeroinitializer
define i32 @f_type(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i64 @stat(i8* %4, %struct.stat* @f_type.st)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %20
8: ; preds = %1
%9 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @f_type.st, i32 0, i32 0)
%10 = call i64 @S_ISREG(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 0, i32* %2
br label %20
13: ; preds = %8
%14 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @f_type.st, i32 0, i32 0)
%15 = call i64 @S_ISDIR(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 1, i32* %2
br label %20
18: ; preds = %13
br label %19
19: ; preds = %18
store i32 -1, i32* %2
br label %20
20: ; preds = %19, %17, %12, %7
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@f_type.st = internal global %struct.stat zeroinitializer
define i32 @f_type(i8* %0) {
%2 = tail call i64 @stat(i8* %0, %struct.stat* @f_type.st)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %13
4: ; preds = %1
%5 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @f_type.st, i64 0, i32 0)
%6 = tail call i64 @S_ISREG(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @f_type.st, i64 0, i32 0)
%10 = tail call i64 @S_ISDIR(i32 %9)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i32 -1, i32 1
br label %13
13: ; preds = %8, %4, %1
%14 = phi i32 [ -1, %1 ], [ 0, %4 ], [ %12, %8 ]
ret i32 %14
}