#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_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISLNK(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *args[]) {
  if (argc < 2) {
    fprintf(stderr, "useage error: %s\n", strerror(errno));
    printf("useage:%s <pathname>\n", args[0]);
    exit(1);
  }
  struct stat st;
  if (lstat(args[1], &st) < 0) {
    fprintf(stderr, "stat error: %s\n", strerror(errno));
    exit(1);
  }
  if (S_ISREG(st.st_mode)) {
    printf("%s is regular file\n", args[1]);
  } else if (S_ISLNK(st.st_mode)) {
    printf("%s is symbol link file\n", args[1]);
  } else if (S_ISDIR(st.st_mode)) {
    printf("%s is a directory\n", args[1]);
  } else if (S_ISBLK(st.st_mode)) {
    printf("%s is block file\n", args[1]);
  } else {
    printf("other case.\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)
cmpl   $0x2,-0x8(%rbp)
jge    11fb <main+0x6b>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe29(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <lstat@plt>
cmp    $0x0,%rax
jge    124c <main+0xbc>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xdeb(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1080 <S_ISREG@plt>
cmp    $0x0,%rax
je     1279 <main+0xe9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    131d <main+0x18d>
mov    -0x18(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     12a6 <main+0x116>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1318 <main+0x188>
mov    -0x18(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12d3 <main+0x143>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1313 <main+0x183>
mov    -0x18(%rbp),%edi
call   1090 <S_ISBLK@plt>
cmp    $0x0,%rax
je     1300 <main+0x170>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    130e <main+0x17e>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1313 <main+0x183>
jmp    1318 <main+0x188>
jmp    131d <main+0x18d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    1247 <main+0xa7>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1070 <lstat@plt>
test   %rax,%rax
js     128a <main+0xea>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     11e0 <main+0x40>
mov    0x8(%rbx),%rsi
lea    0xe5a(%rip),%rdi
jmp    1229 <main+0x89>
mov    %ebp,%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
je     11f9 <main+0x59>
mov    0x8(%rbx),%rsi
lea    0xe55(%rip),%rdi
jmp    1229 <main+0x89>
mov    %ebp,%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     1212 <main+0x72>
mov    0x8(%rbx),%rsi
lea    0xe54(%rip),%rdi
jmp    1229 <main+0x89>
mov    %ebp,%edi
call   10a0 <S_ISBLK@plt>
test   %rax,%rax
je     1239 <main+0x99>
mov    0x8(%rbx),%rsi
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
jmp    1230 <main+0x90>
mov    0x2d92(%rip),%rax
mov    (%rax),%ebp
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd9b(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    (%rbx),%rsi
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd80(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"useage error: %s\0A\00"
@errno = global i32 0
@.str.1 = [22 x i8] c"useage:%s <pathname>\0A\00"
@.str.2 = [16 x i8] c"stat error: %s\0A\00"
@.str.3 = [20 x i8] c"%s is regular file\0A\00"
@.str.4 = [24 x i8] c"%s is symbol link file\0A\00"
@.str.5 = [19 x i8] c"%s is a directory\0A\00"
@.str.6 = [18 x i8] c"%s is block file\0A\00"
@.str.7 = [13 x i8] c"other case.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @lstat(i8* %22, %struct.stat* %6)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %19
%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 %41
36: ; preds = %31
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %39)
br label %76
41: ; preds = %31
%42 = getelementptr inbounds %struct.stat, %struct.stat* %6, 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 %51
46: ; preds = %41
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %49)
br label %75
51: ; preds = %41
%52 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i64 @S_ISDIR(i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %59)
br label %74
61: ; preds = %51
%62 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%63 = load i32, i32* %62
%64 = call i64 @S_ISBLK(i32 %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %61
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %69)
br label %73
71: ; preds = %61
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %73
73: ; preds = %71, %66
br label %74
74: ; preds = %73, %56
br label %75
75: ; preds = %74, %46
br label %76
76: ; preds = %75, %36
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"useage error: %s\0A\00"
@errno = global i32 0
@.str.1 = [22 x i8] c"useage:%s <pathname>\0A\00"
@.str.2 = [16 x i8] c"stat error: %s\0A\00"
@.str.3 = [20 x i8] c"%s is regular file\0A\00"
@.str.4 = [24 x i8] c"%s is symbol link file\0A\00"
@.str.5 = [19 x i8] c"%s is a directory\0A\00"
@.str.6 = [18 x i8] c"%s is block file\0A\00"
@str = [12 x i8] c"other case.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = bitcast %struct.stat* %3 to i8*
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @lstat(i8* %16, %struct.stat* %3)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %13
%26 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%27 = load i32, i32* %26
%28 = tail call i64 @S_ISREG(i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %25
%31 = load i8*, i8** %15
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %53
33: ; preds = %25
%34 = tail call i64 @S_ISLNK(i32 %27)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i8*, i8** %15
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %37)
br label %53
39: ; preds = %33
%40 = tail call i64 @S_ISDIR(i32 %27)
%41 = icmp eq i64 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i8*, i8** %15
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %43)
br label %53
45: ; preds = %39
%46 = tail call i64 @S_ISBLK(i32 %27)
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %45
%49 = load i8*, i8** %15
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %49)
br label %53
51: ; preds = %45
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %53
53: ; preds = %36, %48, %51, %42, %30
ret i32 0
}