#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_ISREG(int /*<<< orphan*/);
scalar_t__ S_ISSOCK(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  char *str;
  int i;
  struct stat buf;
  for (i = 1; i < argc; i++) {
    printf("%s is ", argv[i]);
    if (stat(argv[i], &buf) == -1) {
      perror("fail to stat");
      exit(1);
    }
    if (S_ISREG(buf.st_mode))
      printf("regular file \n");
    else if (S_ISDIR(buf.st_mode))
      printf("directory file\n");
    else if (S_ISCHR(buf.st_mode))
      printf("character special file\n");
    else if (S_ISBLK(buf.st_mode))
      printf("block special file\n");
    else if (S_ISFIFO(buf.st_mode))
      printf("FIFO file\n");
    else if (S_ISSOCK(buf.st_mode))
      printf("socket file\n");
    else
      printf("unkonw\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    132f <main+0x18f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    1217 <main+0x77>
lea    0xdff(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%edi
call   1080 <S_ISREG@plt>
cmp    $0x0,%rax
je     123c <main+0x9c>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    131c <main+0x17c>
mov    -0x20(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1261 <main+0xc1>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1317 <main+0x177>
mov    -0x20(%rbp),%edi
call   1090 <S_ISCHR@plt>
cmp    $0x0,%rax
je     1286 <main+0xe6>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1312 <main+0x172>
mov    -0x20(%rbp),%edi
call   10a0 <S_ISBLK@plt>
cmp    $0x0,%rax
je     12ab <main+0x10b>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    130d <main+0x16d>
mov    -0x20(%rbp),%edi
call   1030 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     12d0 <main+0x130>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1308 <main+0x168>
mov    -0x20(%rbp),%edi
call   1040 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     12f5 <main+0x155>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1303 <main+0x163>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1308 <main+0x168>
jmp    130d <main+0x16d>
jmp    1312 <main+0x172>
jmp    1317 <main+0x177>
jmp    131c <main+0x17c>
jmp    1321 <main+0x181>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bd <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     12a2 <main+0xf2>
mov    %rsi,%r13
mov    %edi,%r12d
mov    $0x1,%ebx
mov    %rsp,%r15
lea    0xe91(%rip),%r14
jmp    11f2 <main+0x42>
nopl   0x0(%rax,%rax,1)
call   1030 <puts@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     12a2 <main+0xf2>
mov    0x0(%r13,%rbx,8),%rsi
lea    0xe02(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r15,%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     12b3 <main+0x103>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   1090 <S_ISREG@plt>
mov    %r14,%rdi
test   %rax,%rax
jne    11e0 <main+0x30>
mov    %ebp,%edi
call   1070 <S_ISDIR@plt>
lea    0xe20(%rip),%rdi
test   %rax,%rax
jne    11e0 <main+0x30>
mov    %ebp,%edi
call   10a0 <S_ISCHR@plt>
lea    0xdf6(%rip),%rdi
test   %rax,%rax
jne    11e0 <main+0x30>
mov    %ebp,%edi
call   10b0 <S_ISBLK@plt>
lea    0xdd0(%rip),%rdi
test   %rax,%rax
jne    11e0 <main+0x30>
mov    %ebp,%edi
call   1040 <S_ISFIFO@plt>
lea    0xdaf(%rip),%rdi
test   %rax,%rax
jne    11e0 <main+0x30>
mov    %ebp,%edi
call   1050 <S_ISSOCK@plt>
test   %rax,%rax
lea    0xd89(%rip),%rdi
lea    0xd7b(%rip),%rax
cmove  %rax,%rdi
jmp    11e0 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4d(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c"%s is \00"
@.str.1 = [13 x i8] c"fail to stat\00"
@.str.2 = [15 x i8] c"regular file \0A\00"
@.str.3 = [16 x i8] c"directory file\0A\00"
@.str.4 = [24 x i8] c"character special file\0A\00"
@.str.5 = [20 x i8] c"block special file\0A\00"
@.str.6 = [11 x i8] c"FIFO file\0A\00"
@.str.7 = [13 x i8] c"socket file\0A\00"
@.str.8 = [8 x i8] c"unkonw\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
br label %9
9: ; preds = %80, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %83
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i8**, i8*** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @stat(i8* %24, %struct.stat* %8)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %13
%28 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %13
%31 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i64 @S_ISREG(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %79
37: ; preds = %30
%38 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i64 @S_ISDIR(i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %78
44: ; preds = %37
%45 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i64 @S_ISCHR(i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %77
51: ; preds = %44
%52 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i64 @S_ISBLK(i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %51
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %76
58: ; preds = %51
%59 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i64 @S_ISFIFO(i32 %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %58
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %75
65: ; preds = %58
%66 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i64 @S_ISSOCK(i32 %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %65
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %74
72: ; preds = %65
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %74
74: ; preds = %72, %70
br label %75
75: ; preds = %74, %63
br label %76
76: ; preds = %75, %56
br label %77
77: ; preds = %76, %49
br label %78
78: ; preds = %77, %42
br label %79
79: ; preds = %78, %35
br label %80
80: ; preds = %79
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 1
store i32 %82, i32* %7
br label %9
83: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"%s is \00"
@.str.1 = [13 x i8] c"fail to stat\00"
@str = [7 x i8] c"unkonw\00"
@str.9 = [12 x i8] c"socket file\00"
@str.10 = [10 x i8] c"FIFO file\00"
@str.11 = [19 x i8] c"block special file\00"
@str.12 = [23 x i8] c"character special file\00"
@str.13 = [15 x i8] c"directory file\00"
@str.14 = [14 x i8] c"regular file \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %45
6: ; preds = %2
%7 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %6, %40
%10 = phi i64 [ 1, %6 ], [ %43, %40 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %11
%15 = call i32 @stat(i8* %14, %struct.stat* %3)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %9
%21 = load i32, i32* %7
%22 = tail call i64 @S_ISREG(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = tail call i64 @S_ISDIR(i32 %21)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %24
%28 = tail call i64 @S_ISCHR(i32 %21)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = tail call i64 @S_ISBLK(i32 %21)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = tail call i64 @S_ISFIFO(i32 %21)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = tail call i64 @S_ISSOCK(i32 %21)
%38 = icmp eq i64 %37, 0
%39 = select i1 %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0)
br label %40
40: ; preds = %36, %33, %30, %27, %24, %20
%41 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.14, i64 0, i64 0), %20 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.13, i64 0, i64 0), %24 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.12, i64 0, i64 0), %27 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.11, i64 0, i64 0), %30 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.10, i64 0, i64 0), %33 ], [ %39, %36 ]
%42 = tail call i32 @puts(i8* dereferenceable(1) %41)
%43 = add nuw nsw i64 %10, 1
%44 = icmp eq i64 %43, %8
br i1 %44, label %45, label %9
45: ; preds = %40, %2
ret i32 0
}