#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*/ errno;
int lstat(char *, struct stat *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct stat buf;
  for (int i = 1; i < argc; i++) {
    int r = 0;
    printf("%s: ", argv[i]);
    r = lstat(argv[i], &buf);
    if (r < 0) {
      strerror(errno);
      continue;
    }
    if (S_ISREG(buf.st_mode)) {
      printf("regular file\n");
    } else if (S_ISDIR(buf.st_mode)) {
      printf("directory\n");
    } else if (S_ISCHR(buf.st_mode)) {
      printf("character special\n");
    } else if (S_ISBLK(buf.st_mode)) {
      printf("block special\n");
    } else if (S_ISFIFO(buf.st_mode)) {
      printf("fifo\n");
    } else if (S_ISLNK(buf.st_mode)) {
      printf("symbolic link\n");
    } else if (S_ISSOCK(buf.st_mode)) {
      printf("socket\n");
    } else {
      printf("** unknown mode **\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    1361 <main+0x1c1>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <lstat@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    121f <main+0x7f>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
jmp    1353 <main+0x1b3>
mov    -0x18(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     1244 <main+0xa4>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    134e <main+0x1ae>
mov    -0x18(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1269 <main+0xc9>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1349 <main+0x1a9>
mov    -0x18(%rbp),%edi
call   10a0 <S_ISCHR@plt>
cmp    $0x0,%rax
je     128e <main+0xee>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1344 <main+0x1a4>
mov    -0x18(%rbp),%edi
call   10b0 <S_ISBLK@plt>
cmp    $0x0,%rax
je     12b3 <main+0x113>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    133f <main+0x19f>
mov    -0x18(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     12d8 <main+0x138>
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    133a <main+0x19a>
mov    -0x18(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     12fd <main+0x15d>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1335 <main+0x195>
mov    -0x18(%rbp),%edi
call   1050 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     1322 <main+0x182>
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1330 <main+0x190>
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1335 <main+0x195>
jmp    133a <main+0x19a>
jmp    133f <main+0x19f>
jmp    1344 <main+0x1a4>
jmp    1349 <main+0x1a9>
jmp    134e <main+0x1ae>
jmp    1353 <main+0x1b3>
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     12da <main+0x12a>
mov    %rsi,%rbx
mov    %edi,%r12d
mov    $0x1,%r13d
lea    0xe29(%rip),%r14
mov    %rsp,%r15
jmp    11fb <main+0x4b>
nopl   0x0(%rax)
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
add    $0x1,%r13
cmp    %r13,%r12
je     12da <main+0x12a>
mov    (%rbx,%r13,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rbx,%r13,8),%rdi
mov    %r15,%rsi
call   1090 <lstat@plt>
test   %eax,%eax
js     11e0 <main+0x30>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   10a0 <S_ISREG@plt>
test   %rax,%rax
je     1240 <main+0x90>
lea    0xe2d(%rip),%rdi
jmp    12d0 <main+0x120>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
call   1080 <S_ISDIR@plt>
test   %rax,%rax
je     1255 <main+0xa5>
lea    0xdff(%rip),%rdi
jmp    12d0 <main+0x120>
mov    %ebp,%edi
call   10b0 <S_ISCHR@plt>
test   %rax,%rax
je     126a <main+0xba>
lea    0xdd8(%rip),%rdi
jmp    12d0 <main+0x120>
mov    %ebp,%edi
call   10c0 <S_ISBLK@plt>
test   %rax,%rax
je     127f <main+0xcf>
lea    0xdb5(%rip),%rdi
jmp    12d0 <main+0x120>
mov    %ebp,%edi
call   1050 <S_ISFIFO@plt>
test   %rax,%rax
je     1294 <main+0xe4>
lea    0xd9b(%rip),%rdi
jmp    12d0 <main+0x120>
mov    %ebp,%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
je     12a9 <main+0xf9>
lea    0xd78(%rip),%rdi
jmp    12d0 <main+0x120>
mov    %ebp,%edi
call   1060 <S_ISSOCK@plt>
test   %rax,%rax
je     12be <main+0x10e>
lea    0xd5c(%rip),%rdi
jmp    12d0 <main+0x120>
lea    0xd40(%rip),%rdi
cs nopw 0x0(%rax,%rax,1)
nop
call   1040 <puts@plt>
jmp    11ee <main+0x3e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"%s: \00"
@errno = global i32 0
@.str.1 = [14 x i8] c"regular file\0A\00"
@.str.2 = [11 x i8] c"directory\0A\00"
@.str.3 = [19 x i8] c"character special\0A\00"
@.str.4 = [15 x i8] c"block special\0A\00"
@.str.5 = [6 x i8] c"fifo\0A\00"
@.str.6 = [15 x i8] c"symbolic link\0A\00"
@.str.7 = [8 x i8] c"socket\0A\00"
@.str.8 = [20 x i8] c"** unknown mode **\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
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 = %89, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %92
13: ; preds = %9
store i32 0, i32* %8
%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 ([5 x i8], [5 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 @lstat(i8* %24, %struct.stat* %6)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %13
%29 = load i32, i32* @errno
%30 = call i32 @strerror(i32 %29)
br label %89
31: ; preds = %13
%32 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i64 @S_ISREG(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %88
38: ; preds = %31
%39 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @S_ISDIR(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %87
45: ; preds = %38
%46 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i64 @S_ISCHR(i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %86
52: ; preds = %45
%53 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i64 @S_ISBLK(i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %85
59: ; preds = %52
%60 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i64 @S_ISFIFO(i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %84
66: ; preds = %59
%67 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%68 = load i32, i32* %67
%69 = call i64 @S_ISLNK(i32 %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %66
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %83
73: ; preds = %66
%74 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%75 = load i32, i32* %74
%76 = call i64 @S_ISSOCK(i32 %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %73
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %82
80: ; preds = %73
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
br label %82
82: ; preds = %80, %78
br label %83
83: ; preds = %82, %71
br label %84
84: ; preds = %83, %64
br label %85
85: ; preds = %84, %57
br label %86
86: ; preds = %85, %50
br label %87
87: ; preds = %86, %43
br label %88
88: ; preds = %87, %36
br label %89
89: ; preds = %88, %28
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %9
92: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"%s: \00"
@errno = global i32 0
@str = [19 x i8] c"** unknown mode **\00"
@str.9 = [7 x i8] c"socket\00"
@str.10 = [14 x i8] c"symbolic link\00"
@str.11 = [5 x i8] c"fifo\00"
@str.12 = [14 x i8] c"block special\00"
@str.13 = [18 x i8] c"character special\00"
@str.14 = [10 x i8] c"directory\00"
@str.15 = [13 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 %9
6: ; preds = %2
%7 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%8 = zext i32 %0 to i64
br label %10
9: ; preds = %59, %2
ret i32 0
10: ; preds = %6, %59
%11 = phi i64 [ 1, %6 ], [ %60, %59 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %12
%16 = call i32 @lstat(i8* %15, %struct.stat* %3)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* @errno
%20 = tail call i32 @strerror(i32 %19)
br label %59
21: ; preds = %10
%22 = load i32, i32* %7
%23 = tail call i64 @S_ISREG(i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.15, i64 0, i64 0))
br label %59
27: ; preds = %21
%28 = tail call i64 @S_ISDIR(i32 %22)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.14, i64 0, i64 0))
br label %59
32: ; preds = %27
%33 = tail call i64 @S_ISCHR(i32 %22)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.13, i64 0, i64 0))
br label %59
37: ; preds = %32
%38 = tail call i64 @S_ISBLK(i32 %22)
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.12, i64 0, i64 0))
br label %59
42: ; preds = %37
%43 = tail call i64 @S_ISFIFO(i32 %22)
%44 = icmp eq i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %42
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.11, i64 0, i64 0))
br label %59
47: ; preds = %42
%48 = tail call i64 @S_ISLNK(i32 %22)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
br label %59
52: ; preds = %47
%53 = tail call i64 @S_ISSOCK(i32 %22)
%54 = icmp eq i64 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %52
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.9, i64 0, i64 0))
br label %59
57: ; preds = %52
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %59
59: ; preds = %25, %35, %45, %55, %57, %50, %40, %30, %18
%60 = add nuw nsw i64 %11, 1
%61 = icmp eq i64 %60, %8
br i1 %61, label %9, label %10
}