#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 st_mode;
};

/* Variables and functions */
int S_IFCHR;
int S_IFDIR;
int S_IFREG;
int stat(char const *, struct stat *);
int al_fnature(const char *spec) {
  struct stat statbuf;
  int r;
  r = stat(spec, &statbuf);
  if (r)
    return 0;
  if (statbuf.st_mode & S_IFCHR)
    return 3;
  if (statbuf.st_mode & S_IFDIR)
    return 2;
  if (statbuf.st_mode & S_IFREG)
    return 1;
  return 4;
}


x86 assembly (clang, -O0):
<al_fnature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1142 <al_fnature+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11ac <al_fnature+0x9c>
mov    -0x18(%rbp),%eax
mov    0x2e8c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1163 <al_fnature+0x53>
movl   $0x3,-0x4(%rbp)
jmp    11ac <al_fnature+0x9c>
mov    -0x18(%rbp),%eax
mov    0x2e5b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1184 <al_fnature+0x74>
movl   $0x2,-0x4(%rbp)
jmp    11ac <al_fnature+0x9c>
mov    -0x18(%rbp),%eax
mov    0x2e5a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11a5 <al_fnature+0x95>
movl   $0x1,-0x4(%rbp)
jmp    11ac <al_fnature+0x9c>
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<al_fnature>:
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     1123 <al_fnature+0x13>
pop    %rcx
ret
mov    (%rsp),%ecx
mov    0x2eab(%rip),%rdx
mov    $0x3,%eax
test   %ecx,(%rdx)
jne    1121 <al_fnature+0x11>
mov    0x2e8b(%rip),%rdx
mov    $0x2,%eax
test   %ecx,(%rdx)
jne    1121 <al_fnature+0x11>
mov    0x2e9b(%rip),%rax
xor    %edx,%edx
test   %ecx,(%rax)
sete   %dl
lea    (%rdx,%rdx,2),%eax
add    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFCHR = global i32 0
@S_IFDIR = global i32 0
@S_IFREG = global i32 0
define i32 @al_fnature(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @stat(i8* %6, %struct.stat* %4)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %33
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* @S_IFCHR
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 3, i32* %2
br label %33
18: ; preds = %11
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load i32, i32* @S_IFDIR
%22 = and i32 %20, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 2, i32* %2
br label %33
25: ; preds = %18
%26 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load i32, i32* @S_IFREG
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 1, i32* %2
br label %33
32: ; preds = %25
store i32 4, i32* %2
br label %33
33: ; preds = %32, %31, %24, %17, %10
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFCHR = global i32 0
@S_IFDIR = global i32 0
@S_IFREG = global i32 0
define i32 @al_fnature(i8* nocapture %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, 0
br i1 %5, label %6, label %21
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @S_IFCHR
%10 = and i32 %9, %8
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %6
%13 = load i32, i32* @S_IFDIR
%14 = and i32 %13, %8
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* @S_IFREG
%18 = and i32 %17, %8
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i32 4, i32 1
br label %21
21: ; preds = %16, %12, %6, %1
%22 = phi i32 [ 0, %1 ], [ 3, %6 ], [ 2, %12 ], [ %20, %16 ]
ret i32 %22
}