#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_rdev;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISBLK(int /*<<< orphan*/);
scalar_t__ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int major(int /*<<< orphan*/);
int minor(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct stat sbuf;
  char *devtype;
  if (argc != 2) {
    fprintf(stderr, "usage: %s path\n", argv[0]);
    exit(1);
  }
  if (stat(argv[1], &sbuf) < 0) {
    fprintf(stderr, "%s: stat: %s\n", argv[1], strerror(errno));
    exit(1);
  }
  if (S_ISCHR(sbuf.st_mode))
    devtype = "char";
  else if (S_ISBLK(sbuf.st_mode))
    devtype = "block";
  else {
    fprintf(stderr, "%s is not a block or character device\n", argv[1]);
    exit(1);
  }
  printf("%s: major: %d, minor: %d\n", devtype, major(sbuf.st_rdev),
         minor(sbuf.st_rdev));
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d8 <main+0x48>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jge    123b <main+0xab>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1080 <S_ISCHR@plt>
cmp    $0x0,%rax
je     125d <main+0xcd>
lea    0xdca(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12ad <main+0x11d>
mov    -0x14(%rbp),%edi
call   1090 <S_ISBLK@plt>
cmp    $0x0,%rax
je     127f <main+0xef>
lea    0xdad(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    12a8 <main+0x118>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12ad <main+0x11d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <major@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <minor@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    %eax,%ecx
lea    0xd78(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11e7 <main+0x57>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1070 <stat@plt>
test   %rax,%rax
jns    120b <main+0x7b>
mov    0x2e2d(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe42(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe06(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x4(%rsp),%edi
call   1080 <S_ISCHR@plt>
test   %rax,%rax
jne    123d <main+0xad>
mov    0x4(%rsp),%edi
call   1090 <S_ISBLK@plt>
test   %rax,%rax
jne    1246 <main+0xb6>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdee(%rip),%rsi
jmp    11fa <main+0x6a>
lea    0xdda(%rip),%rbx
jmp    124d <main+0xbd>
lea    0xdd6(%rip),%rbx
mov    (%rsp),%edi
call   1050 <major@plt>
mov    %eax,%ebp
mov    (%rsp),%edi
call   1030 <minor@plt>
lea    0xdea(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@stderr = global i32 0
@.str = [16 x i8] c"usage: %s path\0A\00"
@.str.1 = [14 x i8] c"%s: stat: %s\0A\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"char\00"
@.str.3 = [6 x i8] c"block\00"
@.str.4 = [39 x i8] c"%s is not a block or character device\0A\00"
@.str.5 = [26 x i8] c"%s: major: %d, minor: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @stat(i8* %20, %struct.stat* %6)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
%33 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%34 = load i32, i32* %33
%35 = call i64 @S_ISCHR(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %52
38: ; preds = %32
%39 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%40 = load i32, i32* %39
%41 = call i64 @S_ISBLK(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %38
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %51
44: ; preds = %38
%45 = load i32, i32* @stderr
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %43
br label %52
52: ; preds = %51, %37
%53 = load i8*, i8** %7
%54 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @major(i32 %55)
%57 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @minor(i32 %58)
%60 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %53, i32 %56, i32 %59)
%61 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@stderr = global i32 0
@.str = [16 x i8] c"usage: %s path\0A\00"
@.str.1 = [14 x i8] c"%s: stat: %s\0A\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"char\00"
@.str.3 = [6 x i8] c"block\00"
@.str.4 = [39 x i8] c"%s is not a block or character device\0A\00"
@.str.5 = [26 x i8] c"%s: major: %d, minor: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @stat(i8* %13, %struct.stat* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %11
%24 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%25 = load i32, i32* %24
%26 = call i64 @S_ISCHR(i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = load i32, i32* %24
%30 = call i64 @S_ISBLK(i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %12
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %28, %23
%38 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %23 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %28 ]
%39 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @major(i32 %40)
%42 = load i32, i32* %39
%43 = call i32 @minor(i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %38, i32 %41, i32 %43)
%45 = call i32 @exit(i32 0)
unreachable
}