#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;
};
typedef int mode_t;

/* Variables and functions */
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISFIFO(int);
scalar_t__ S_ISLNK(int);
scalar_t__ S_ISSOCK(int);
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
char getclass(struct stat stats) {
  mode_t mode = stats.st_mode;
  if (S_ISDIR(mode))
    return '/';
  if (S_ISLNK(mode))
    return '@';
  if (S_ISSOCK(mode))
    return '=';
  if (S_ISFIFO(mode))
    return '|';
  if (mode & S_IXUSR || mode & S_IXGRP || mode & S_IXOTH)
    return '*';
  return '\0';
}


x86 assembly (clang, -O0):
<getclass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     116c <getclass+0x2c>
movb   $0x2f,-0x1(%rbp)
jmp    1209 <getclass+0xc9>
mov    -0xc(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1187 <getclass+0x47>
movb   $0x40,-0x1(%rbp)
jmp    1209 <getclass+0xc9>
mov    -0xc(%rbp),%edi
call   1050 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     11a2 <getclass+0x62>
movb   $0x3d,-0x1(%rbp)
jmp    1209 <getclass+0xc9>
mov    -0xc(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     11bd <getclass+0x7d>
movb   $0x7c,-0x1(%rbp)
jmp    1209 <getclass+0xc9>
mov    -0xc(%rbp),%eax
mov    0x2e19(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11fc <getclass+0xbc>
mov    -0xc(%rbp),%eax
mov    0x2dfc(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11fc <getclass+0xbc>
mov    -0xc(%rbp),%eax
mov    0x2df7(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1205 <getclass+0xc5>
movb   $0x2a,-0x1(%rbp)
jmp    1209 <getclass+0xc9>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getclass>:
push   %rbx
mov    %edi,%ebx
call   1060 <S_ISDIR@plt>
mov    %rax,%rcx
mov    $0x2f,%al
test   %rcx,%rcx
je     1154 <getclass+0x14>
pop    %rbx
ret
mov    %ebx,%edi
call   1030 <S_ISLNK@plt>
mov    %rax,%rcx
mov    $0x40,%al
test   %rcx,%rcx
jne    1152 <getclass+0x12>
mov    %ebx,%edi
call   1050 <S_ISSOCK@plt>
mov    %rax,%rcx
mov    $0x3d,%al
test   %rcx,%rcx
jne    1152 <getclass+0x12>
mov    %ebx,%edi
call   1040 <S_ISFIFO@plt>
mov    %rax,%rcx
mov    $0x7c,%al
test   %rcx,%rcx
jne    1152 <getclass+0x12>
mov    0x2e52(%rip),%rcx
mov    $0x2a,%al
test   %ebx,(%rcx)
jne    1152 <getclass+0x12>
mov    0x2e3d(%rip),%rcx
test   %ebx,(%rcx)
jne    1152 <getclass+0x12>
mov    0x2e42(%rip),%rax
and    (%rax),%ebx
mov    $0x2a,%eax
cmove  %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
define signext i8 @getclass(i32 %0) {
%2 = alloca i8
%3 = alloca %struct.stat
%4 = alloca i32
%5 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
store i32 %0, i32* %5
%6 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%7 = load i32, i32* %6
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = call i64 @S_ISDIR(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8 47, i8* %2
br label %44
12: ; preds = %1
%13 = load i32, i32* %4
%14 = call i64 @S_ISLNK(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i8 64, i8* %2
br label %44
17: ; preds = %12
%18 = load i32, i32* %4
%19 = call i64 @S_ISSOCK(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i8 61, i8* %2
br label %44
22: ; preds = %17
%23 = load i32, i32* %4
%24 = call i64 @S_ISFIFO(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i8 124, i8* %2
br label %44
27: ; preds = %22
%28 = load i32, i32* %4
%29 = load i32, i32* @S_IXUSR
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %42, label %32
32: ; preds = %27
%33 = load i32, i32* %4
%34 = load i32, i32* @S_IXGRP
%35 = and i32 %33, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %32
%38 = load i32, i32* %4
%39 = load i32, i32* @S_IXOTH
%40 = and i32 %38, %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %37, %32, %27
store i8 42, i8* %2
br label %44
43: ; preds = %37
store i8 0, i8* %2
br label %44
44: ; preds = %43, %42, %26, %21, %16, %11
%45 = load i8, i8* %2
ret i8 %45
}

LLVM IR (-O2):
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
define signext i8 @getclass(i32 %0) {
%2 = tail call i64 @S_ISDIR(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %26
4: ; preds = %1
%5 = tail call i64 @S_ISLNK(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %4
%8 = tail call i64 @S_ISSOCK(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = tail call i64 @S_ISFIFO(i32 %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i32, i32* @S_IXUSR
%15 = and i32 %14, %0
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32, i32* @S_IXGRP
%19 = and i32 %18, %0
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* @S_IXOTH
%23 = and i32 %22, %0
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8 0, i8 42
br label %26
26: ; preds = %21, %13, %17, %10, %7, %4, %1
%27 = phi i8 [ 47, %1 ], [ 64, %4 ], [ 61, %7 ], [ 124, %10 ], [ 42, %17 ], [ 42, %13 ], [ %25, %21 ]
ret i8 %27
}