#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_ISBLK(int /*<<< orphan*/);
scalar_t__ S_ISCHR(int /*<<< orphan*/);
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISFIFO(int /*<<< orphan*/);
scalar_t__ S_ISLNK(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ S_ISSOCK(int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
void compute_ftype(const struct stat *buf, char *ftype) {
  if (S_ISREG(buf->st_mode)) {
    strcpy(ftype, "FILE");
  } else if (S_ISDIR(buf->st_mode)) {
    strcpy(ftype, "DIR");
  } else if (S_ISCHR(buf->st_mode)) {
    strcpy(ftype, "CHR");
  } else if (S_ISFIFO(buf->st_mode)) {
    strcpy(ftype, "FIFO");
  } else if (S_ISLNK(buf->st_mode)) {
    strcpy(ftype, "LINK");
  } else if (S_ISBLK(buf->st_mode)) {
    strcpy(ftype, "BLK");
  } else if (S_ISSOCK(buf->st_mode)) {
    strcpy(ftype, "SOCK");
  } else {
    strcpy(ftype, "UNKO");
  }
}


x86 assembly (clang, -O0):
<compute_ftype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1080 <S_ISREG@plt>
cmp    $0x0,%rax
je     11ba <compute_ftype+0x3a>
mov    -0x10(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12e4 <compute_ftype+0x164>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11e4 <compute_ftype+0x64>
mov    -0x10(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12df <compute_ftype+0x15f>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1090 <S_ISCHR@plt>
cmp    $0x0,%rax
je     120e <compute_ftype+0x8e>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12da <compute_ftype+0x15a>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     1238 <compute_ftype+0xb8>
mov    -0x10(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12d5 <compute_ftype+0x155>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1262 <compute_ftype+0xe2>
mov    -0x10(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12d0 <compute_ftype+0x150>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   10a0 <S_ISBLK@plt>
cmp    $0x0,%rax
je     128c <compute_ftype+0x10c>
mov    -0x10(%rbp),%rdi
lea    0xd95(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12cb <compute_ftype+0x14b>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     12b6 <compute_ftype+0x136>
mov    -0x10(%rbp),%rdi
lea    0xd6f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12c6 <compute_ftype+0x146>
mov    -0x10(%rbp),%rdi
lea    0xd5f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12cb <compute_ftype+0x14b>
jmp    12d0 <compute_ftype+0x150>
jmp    12d5 <compute_ftype+0x155>
jmp    12da <compute_ftype+0x15a>
jmp    12df <compute_ftype+0x15f>
jmp    12e4 <compute_ftype+0x164>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_ftype>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1080 <S_ISREG@plt>
test   %rax,%rax
je     11a2 <compute_ftype+0x22>
lea    0xe63(%rip),%rsi
jmp    1227 <compute_ftype+0xa7>
mov    (%rbx),%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     11b7 <compute_ftype+0x37>
lea    0xe50(%rip),%rsi
jmp    1227 <compute_ftype+0xa7>
mov    (%rbx),%edi
call   1090 <S_ISCHR@plt>
test   %rax,%rax
je     11cc <compute_ftype+0x4c>
lea    0xe3f(%rip),%rsi
jmp    1227 <compute_ftype+0xa7>
mov    (%rbx),%edi
call   1050 <S_ISFIFO@plt>
test   %rax,%rax
je     11e1 <compute_ftype+0x61>
lea    0xe2e(%rip),%rsi
jmp    1227 <compute_ftype+0xa7>
mov    (%rbx),%edi
call   1040 <S_ISLNK@plt>
test   %rax,%rax
je     11f6 <compute_ftype+0x76>
lea    0xe1e(%rip),%rsi
jmp    1227 <compute_ftype+0xa7>
mov    (%rbx),%edi
call   10a0 <S_ISBLK@plt>
test   %rax,%rax
je     120b <compute_ftype+0x8b>
lea    0xe0e(%rip),%rsi
jmp    1227 <compute_ftype+0xa7>
mov    (%rbx),%edi
call   1060 <S_ISSOCK@plt>
test   %rax,%rax
lea    0xe04(%rip),%rax
lea    0xdf8(%rip),%rsi
cmove  %rax,%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"FILE\00"
@.str.1 = [4 x i8] c"DIR\00"
@.str.2 = [4 x i8] c"CHR\00"
@.str.3 = [5 x i8] c"FIFO\00"
@.str.4 = [5 x i8] c"LINK\00"
@.str.5 = [4 x i8] c"BLK\00"
@.str.6 = [5 x i8] c"SOCK\00"
@.str.7 = [5 x i8] c"UNKO\00"
define void @compute_ftype(%struct.stat* %0, i8* %1) {
%3 = alloca %struct.stat*
%4 = alloca i8*
store %struct.stat* %0, %struct.stat** %3
store i8* %1, i8** %4
%5 = load %struct.stat*, %struct.stat** %3
%6 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = call i64 @S_ISREG(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %76
13: ; preds = %2
%14 = load %struct.stat*, %struct.stat** %3
%15 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @S_ISDIR(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %75
22: ; preds = %13
%23 = load %struct.stat*, %struct.stat** %3
%24 = getelementptr inbounds %struct.stat, %struct.stat* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i64 @S_ISCHR(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %74
31: ; preds = %22
%32 = load %struct.stat*, %struct.stat** %3
%33 = getelementptr inbounds %struct.stat, %struct.stat* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @S_ISFIFO(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i8*, i8** %4
%39 = call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %73
40: ; preds = %31
%41 = load %struct.stat*, %struct.stat** %3
%42 = getelementptr inbounds %struct.stat, %struct.stat* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i64 @S_ISLNK(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i8*, i8** %4
%48 = call i32 @strcpy(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %72
49: ; preds = %40
%50 = load %struct.stat*, %struct.stat** %3
%51 = getelementptr inbounds %struct.stat, %struct.stat* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i64 @S_ISBLK(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = load i8*, i8** %4
%57 = call i32 @strcpy(i8* %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %71
58: ; preds = %49
%59 = load %struct.stat*, %struct.stat** %3
%60 = getelementptr inbounds %struct.stat, %struct.stat* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i64 @S_ISSOCK(i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %58
%65 = load i8*, i8** %4
%66 = call i32 @strcpy(i8* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %70
67: ; preds = %58
%68 = load i8*, i8** %4
%69 = call i32 @strcpy(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %70
70: ; preds = %67, %64
br label %71
71: ; preds = %70, %55
br label %72
72: ; preds = %71, %46
br label %73
73: ; preds = %72, %37
br label %74
74: ; preds = %73, %28
br label %75
75: ; preds = %74, %19
br label %76
76: ; preds = %75, %10
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"FILE\00"
@.str.1 = [4 x i8] c"DIR\00"
@.str.2 = [4 x i8] c"CHR\00"
@.str.3 = [5 x i8] c"FIFO\00"
@.str.4 = [5 x i8] c"LINK\00"
@.str.5 = [4 x i8] c"BLK\00"
@.str.6 = [5 x i8] c"SOCK\00"
@.str.7 = [5 x i8] c"UNKO\00"
define void @compute_ftype(%struct.stat* nocapture %0, i8* %1) {
%3 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call i64 @S_ISREG(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %32
7: ; preds = %2
%8 = load i32, i32* %3
%9 = tail call i64 @S_ISDIR(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %32
11: ; preds = %7
%12 = load i32, i32* %3
%13 = tail call i64 @S_ISCHR(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = load i32, i32* %3
%17 = tail call i64 @S_ISFIFO(i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i32, i32* %3
%21 = tail call i64 @S_ISLNK(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i32, i32* %3
%25 = tail call i64 @S_ISBLK(i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* %3
%29 = tail call i64 @S_ISSOCK(i32 %28)
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0)
br label %32
32: ; preds = %27, %23, %19, %15, %11, %7, %2
%33 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %11 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %15 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %19 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), %23 ], [ %31, %27 ]
%34 = tail call i32 @strcpy(i8* %1, i8* %33)
ret void
}