#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;
  scalar_t__ st_rdev;
};

/* Variables and functions */
#define S_IFBLK 132
#define S_IFCHR 131
#define S_IFDIR 130
#define S_IFIFO 129
int S_IFMT;
#define S_IFREG 128
int S_ISGID;
int S_ISUID;
int S_ISVTX;
int /*<<< orphan*/ printf(char *, ...);
void Print_FileTypeAndPermissions(struct stat *pststat) {
  switch (pststat->st_mode & S_IFMT) {
  case S_IFDIR:
    printf("This is a Directory.\n");
    break;
  case S_IFREG:
    printf("This is a Regular file.\n");
    break;
  case S_IFCHR:
    printf("This is a Character device.\n");
    printf("\tSpecial device: %d.\n", (int)pststat->st_rdev);
    break;
  case S_IFBLK:
    printf("This is a Block device.\n");
    printf("\tSpecial device: %d.\n", (int)pststat->st_rdev);
    break;
  case S_IFIFO:
    printf("This is a named PIPO file.\n");
    break;
  default:
    printf("Unknown type of file.\n");
    break;
  }
  if (pststat->st_mode & S_ISUID) {
    printf("\tSet UID.\n");
  }
  if (pststat->st_mode & S_ISGID) {
    printf("\tSet GID.\n");
  }
  if (pststat->st_mode & S_ISVTX) {
    printf("\tSet Sticky.\n");
  }
  printf("\tPermission : %o.\n", pststat->st_mode & 0777);
  return;
}


x86 assembly (clang, -O0):
<Print_FileTypeAndPermissions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x4,%eax
ja     11e2 <Print_FileTypeAndPermissions+0xd2>
mov    -0x10(%rbp),%rax
lea    0xeb6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f0 <Print_FileTypeAndPermissions+0xe0>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f0 <Print_FileTypeAndPermissions+0xe0>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%esi
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f0 <Print_FileTypeAndPermissions+0xe0>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f0 <Print_FileTypeAndPermissions+0xe0>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f0 <Print_FileTypeAndPermissions+0xe0>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2de3(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1216 <Print_FileTypeAndPermissions+0x106>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2da5(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     123c <Print_FileTypeAndPermissions+0x12c>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2d9f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1262 <Print_FileTypeAndPermissions+0x152>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
and    $0x1ff,%esi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Print_FileTypeAndPermissions>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
and    (%rdi),%eax
add    $0xffffff80,%eax
cmp    $0x4,%eax
ja     1150 <Print_FileTypeAndPermissions+0x30>
lea    0xec2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf5f(%rip),%rdi
jmp    1169 <Print_FileTypeAndPermissions+0x49>
lea    0xf83(%rip),%rdi
jmp    1169 <Print_FileTypeAndPermissions+0x49>
lea    0xedd(%rip),%rdi
jmp    1169 <Print_FileTypeAndPermissions+0x49>
lea    0xf5c(%rip),%rdi
call   1030 <puts@plt>
jmp    1196 <Print_FileTypeAndPermissions+0x76>
lea    0xf1a(%rip),%rdi
jmp    1180 <Print_FileTypeAndPermissions+0x60>
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%esi
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
mov    0x2e41(%rip),%rax
test   %esi,(%rax)
je     11b1 <Print_FileTypeAndPermissions+0x91>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%esi
mov    0x2e10(%rip),%rax
test   %esi,(%rax)
je     11ca <Print_FileTypeAndPermissions+0xaa>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%esi
mov    0x2e17(%rip),%rax
test   %esi,(%rax)
je     11e3 <Print_FileTypeAndPermissions+0xc3>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%esi
and    $0x1ff,%esi
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
@S_IFMT = global i32 0
@.str = [22 x i8] c"This is a Directory.\0A\00"
@.str.1 = [25 x i8] c"This is a Regular file.\0A\00"
@.str.2 = [29 x i8] c"This is a Character device.\0A\00"
@.str.3 = [22 x i8] c"\09Special device: %d.\0A\00"
@.str.4 = [25 x i8] c"This is a Block device.\0A\00"
@.str.5 = [28 x i8] c"This is a named PIPO file.\0A\00"
@.str.6 = [23 x i8] c"Unknown type of file.\0A\00"
@S_ISUID = global i32 0
@.str.7 = [11 x i8] c"\09Set UID.\0A\00"
@S_ISGID = global i32 0
@.str.8 = [11 x i8] c"\09Set GID.\0A\00"
@S_ISVTX = global i32 0
@.str.9 = [14 x i8] c"\09Set Sticky.\0A\00"
@.str.10 = [19 x i8] c"\09Permission : %o.\0A\00"
define void @Print_FileTypeAndPermissions(%struct.stat* %0) {
%2 = alloca %struct.stat*
store %struct.stat* %0, %struct.stat** %2
%3 = load %struct.stat*, %struct.stat** %2
%4 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%5 = load i32, i32* %4
%6 = load i32, i32* @S_IFMT
%7 = and i32 %5, %6
switch i32 %7, label %28 [
i32 130, label %8
i32 128, label %10
i32 131, label %12
i32 132, label %19
i32 129, label %26
]
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %30
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %30
12: ; preds = %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%14 = load %struct.stat*, %struct.stat** %2
%15 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 1
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %30
19: ; preds = %1
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%21 = load %struct.stat*, %struct.stat** %2
%22 = getelementptr inbounds %struct.stat, %struct.stat* %21, i32 0, i32 1
%23 = load i64, i64* %22
%24 = trunc i64 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %30
26: ; preds = %1
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %30
28: ; preds = %1
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %30
30: ; preds = %28, %26, %19, %12, %10, %8
%31 = load %struct.stat*, %struct.stat** %2
%32 = getelementptr inbounds %struct.stat, %struct.stat* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = load i32, i32* @S_ISUID
%35 = and i32 %33, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
%40 = load %struct.stat*, %struct.stat** %2
%41 = getelementptr inbounds %struct.stat, %struct.stat* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = load i32, i32* @S_ISGID
%44 = and i32 %42, %43
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %48
48: ; preds = %46, %39
%49 = load %struct.stat*, %struct.stat** %2
%50 = getelementptr inbounds %struct.stat, %struct.stat* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = load i32, i32* @S_ISVTX
%53 = and i32 %51, %52
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %57
57: ; preds = %55, %48
%58 = load %struct.stat*, %struct.stat** %2
%59 = getelementptr inbounds %struct.stat, %struct.stat* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = and i32 %60, 511
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 %61)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
@S_IFMT = global i32 0
@.str.3 = [22 x i8] c"\09Special device: %d.\0A\00"
@S_ISUID = global i32 0
@S_ISGID = global i32 0
@S_ISVTX = global i32 0
@.str.10 = [19 x i8] c"\09Permission : %o.\0A\00"
@str = [27 x i8] c"This is a named PIPO file.\00"
@str.11 = [13 x i8] c"\09Set Sticky.\00"
@str.12 = [10 x i8] c"\09Set GID.\00"
@str.13 = [10 x i8] c"\09Set UID.\00"
@str.14 = [24 x i8] c"This is a Block device.\00"
@str.15 = [28 x i8] c"This is a Character device.\00"
@str.16 = [24 x i8] c"This is a Regular file.\00"
@str.17 = [21 x i8] c"This is a Directory.\00"
@str.18 = [22 x i8] c"Unknown type of file.\00"
define void @Print_FileTypeAndPermissions(%struct.stat* nocapture %0) {
%2 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = load i32, i32* @S_IFMT
%5 = and i32 %4, %3
switch i32 %5, label %24 [
i32 130, label %6
i32 128, label %8
i32 131, label %10
i32 132, label %16
i32 129, label %22
]
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.17, i64 0, i64 0))
br label %26
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.16, i64 0, i64 0))
br label %26
10: ; preds = %1
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.15, i64 0, i64 0))
%12 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 1
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %26
16: ; preds = %1
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
%18 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 1
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %26
22: ; preds = %1
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %26
24: ; preds = %1
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.18, i64 0, i64 0))
br label %26
26: ; preds = %24, %22, %16, %10, %8, %6
%27 = load i32, i32* %2
%28 = load i32, i32* @S_ISUID
%29 = and i32 %28, %27
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.13, i64 0, i64 0))
%33 = load i32, i32* %2
br label %34
34: ; preds = %31, %26
%35 = phi i32 [ %33, %31 ], [ %27, %26 ]
%36 = load i32, i32* @S_ISGID
%37 = and i32 %36, %35
%38 = icmp eq i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %34
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.12, i64 0, i64 0))
%41 = load i32, i32* %2
br label %42
42: ; preds = %39, %34
%43 = phi i32 [ %41, %39 ], [ %35, %34 ]
%44 = load i32, i32* @S_ISVTX
%45 = and i32 %44, %43
%46 = icmp eq i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %42
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.11, i64 0, i64 0))
%49 = load i32, i32* %2
br label %50
50: ; preds = %47, %42
%51 = phi i32 [ %49, %47 ], [ %43, %42 ]
%52 = and i32 %51, 511
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 %52)
ret void
}