#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 */
typedef int uint16_t;

/* Variables and functions */
int S_IFBLK;
int S_IFCHR;
int S_IFIFO;
int atoi(char *);
scalar_t__ errno;
scalar_t__ mknod(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ writes(char *);
int main(int argc, char *argv[]) {
  uint16_t mode;
  uint16_t dev;
  if (argc != 3 && argc != 5)
    goto usage;
  if (argv[2][1])
    goto badtype;
  switch (*argv[2]) {
  case 'b':
    mode = S_IFBLK | 0777;
    break;
  case 'c':
    mode = S_IFCHR | 0777;
    break;
  case 'p':
    mode = S_IFIFO | 0777;
    break;
  default:
    goto badtype;
  }
  if (*argv[2] != 'p') {
    if (argc != 5)
      goto usage;
    errno = 0;
    dev = atoi(argv[3]) << 8;
    dev |= atoi(argv[4]);
    if (errno)
      goto usage;
  } else if (argc != 3)
    goto usage;
  if (mknod(argv[1], mode, dev) != 0) {
    perror(argv[1]);
    return 1;
  }
  return 0;
badtype:
  writes("mknod: invalid type (must be b c or p)\n");
  return 1;
usage:
  writes("usage: mknod path type {major minor}\n");
  return 1;
}


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   $0x3,-0x8(%rbp)
je     116f <main+0x2f>
cmpl   $0x5,-0x8(%rbp)
je     116f <main+0x2f>
jmp    12eb <main+0x1ab>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
cmpb   $0x0,0x1(%rax)
je     1186 <main+0x46>
jmp    12d3 <main+0x193>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x62,%eax
je     11c4 <main+0x84>
jmp    11a2 <main+0x62>
mov    -0x1c(%rbp),%eax
sub    $0x63,%eax
je     11da <main+0x9a>
jmp    11b3 <main+0x73>
mov    -0x1c(%rbp),%eax
sub    $0x70,%eax
je     11f0 <main+0xb0>
jmp    1206 <main+0xc6>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
or     $0x1ff,%eax
mov    %eax,-0x14(%rbp)
jmp    120b <main+0xcb>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
or     $0x1ff,%eax
mov    %eax,-0x14(%rbp)
jmp    120b <main+0xcb>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
or     $0x1ff,%eax
mov    %eax,-0x14(%rbp)
jmp    120b <main+0xcb>
jmp    12d3 <main+0x193>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
je     127d <main+0x13d>
cmpl   $0x5,-0x8(%rbp)
je     122e <main+0xee>
jmp    12eb <main+0x1ab>
mov    0x2d9b(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
shl    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1060 <atoi@plt>
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d67(%rip),%rax
cmpq   $0x0,(%rax)
je     1278 <main+0x138>
jmp    12eb <main+0x1ab>
jmp    1291 <main+0x151>
cmpl   $0x3,-0x8(%rbp)
je     128c <main+0x14c>
jmp    12eb <main+0x1ab>
jmp    1291 <main+0x151>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <mknod@plt>
cmp    $0x0,%rax
je     12c7 <main+0x187>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fe <main+0x1be>
movl   $0x0,-0x4(%rbp)
jmp    12fe <main+0x1be>
lea    0xd26(%rip),%rdi
call   1030 <writes@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fe <main+0x1be>
lea    0xd36(%rip),%rdi
call   1030 <writes@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x5,%edi
je     1155 <main+0x15>
cmp    $0x3,%edi
jne    11fc <main+0xbc>
mov    0x10(%rbx),%rax
cmpb   $0x0,0x1(%rax)
je     116b <main+0x2b>
lea    0xe9a(%rip),%rdi
jmp    1203 <main+0xc3>
mov    (%rax),%al
movsbl %al,%ecx
cmp    $0x62,%ecx
je     118c <main+0x4c>
cmp    $0x70,%ecx
je     1199 <main+0x59>
cmp    $0x63,%ecx
jne    115f <main+0x1f>
mov    0x2e52(%rip),%rcx
cmp    $0x70,%al
jne    11a4 <main+0x64>
jmp    11fc <main+0xbc>
mov    0x2e4d(%rip),%rcx
cmp    $0x70,%al
jne    11a4 <main+0x64>
jmp    11fc <main+0xbc>
mov    0x2e28(%rip),%rcx
cmp    $0x70,%al
je     11fc <main+0xbc>
cmp    $0x5,%edi
jne    11fc <main+0xbc>
mov    $0x1ff,%r14d
or     (%rcx),%r14d
mov    0x2e17(%rip),%rax
movq   $0x0,(%rax)
mov    0x18(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
mov    0x20(%rbx),%rdi
call   1060 <atoi@plt>
or     %eax,%ebp
mov    0x8(%rbx),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1040 <mknod@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     120d <main+0xcd>
mov    0x8(%rbx),%rdi
call   1050 <perror@plt>
jmp    1208 <main+0xc8>
lea    0xe25(%rip),%rdi
call   1030 <writes@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@S_IFBLK = global i32 0
@S_IFCHR = global i32 0
@S_IFIFO = global i32 0
@errno = global i64 0
@.str = [40 x i8] c"mknod: invalid type (must be b c or p)\0A\00"
@.str.1 = [38 x i8] c"usage: mknod path type {major minor}\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
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, 3
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 5
br i1 %12, label %13, label %14
13: ; preds = %10
br label %86
14: ; preds = %10, %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %84
22: ; preds = %14
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %37 [
i32 98, label %28
i32 99, label %31
i32 112, label %34
]
28: ; preds = %22
%29 = load i32, i32* @S_IFBLK
%30 = or i32 %29, 511
store i32 %30, i32* %6
br label %38
31: ; preds = %22
%32 = load i32, i32* @S_IFCHR
%33 = or i32 %32, 511
store i32 %33, i32* %6
br label %38
34: ; preds = %22
%35 = load i32, i32* @S_IFIFO
%36 = or i32 %35, 511
store i32 %36, i32* %6
br label %38
37: ; preds = %22
br label %84
38: ; preds = %34, %31, %28
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 112
br i1 %44, label %45, label %65
45: ; preds = %38
%46 = load i32, i32* %4
%47 = icmp ne i32 %46, 5
br i1 %47, label %48, label %49
48: ; preds = %45
br label %86
49: ; preds = %45
store i64 0, i64* @errno
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 3
%52 = load i8*, i8** %51
%53 = call i32 @atoi(i8* %52)
%54 = shl i32 %53, 8
store i32 %54, i32* %7
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 4
%57 = load i8*, i8** %56
%58 = call i32 @atoi(i8* %57)
%59 = load i32, i32* %7
%60 = or i32 %59, %58
store i32 %60, i32* %7
%61 = load i64, i64* @errno
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %49
br label %86
64: ; preds = %49
br label %70
65: ; preds = %38
%66 = load i32, i32* %4
%67 = icmp ne i32 %66, 3
br i1 %67, label %68, label %69
68: ; preds = %65
br label %86
69: ; preds = %65
br label %70
70: ; preds = %69, %64
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = load i32, i32* %6
%75 = load i32, i32* %7
%76 = call i64 @mknod(i8* %73, i32 %74, i32 %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %70
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32 @perror(i8* %81)
store i32 1, i32* %3
br label %88
83: ; preds = %70
store i32 0, i32* %3
br label %88
84: ; preds = %37, %21
%85 = call i32 @writes(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %88
86: ; preds = %68, %63, %48, %13
%87 = call i32 @writes(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %88
88: ; preds = %86, %84, %83, %78
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@S_IFBLK = global i32 0
@S_IFCHR = global i32 0
@S_IFIFO = global i32 0
@errno = global i64 0
@.str = [40 x i8] c"mknod: invalid type (must be b c or p)\0A\00"
@.str.1 = [38 x i8] c"usage: mknod path type {major minor}\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp ne i32 %0, 3
%4 = icmp eq i32 %0, 5
switch i32 %0, label %41 [
i32 5, label %5
i32 3, label %5
]
5: ; preds = %2, %2
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %39
11: ; preds = %5
%12 = load i8, i8* %7
%13 = sext i8 %12 to i32
switch i32 %13, label %39 [
i32 98, label %16
i32 99, label %14
i32 112, label %15
]
14: ; preds = %11
br label %16
15: ; preds = %11
br label %16
16: ; preds = %11, %15, %14
%17 = phi i32* [ @S_IFIFO, %15 ], [ @S_IFCHR, %14 ], [ @S_IFBLK, %11 ]
%18 = load i32, i32* %17
%19 = or i32 %18, 511
%20 = icmp eq i8 %12, 112
br i1 %20, label %35, label %21
21: ; preds = %16
br i1 %4, label %22, label %41
22: ; preds = %21
store i64 0, i64* @errno
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = shl i32 %25, 8
%27 = getelementptr inbounds i8*, i8** %1, i64 4
%28 = load i8*, i8** %27
%29 = tail call i32 @atoi(i8* %28)
%30 = or i32 %29, %26
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = tail call i64 @mknod(i8* %32, i32 %19, i32 %30)
%34 = icmp eq i64 %33, 0
br i1 %34, label %43, label %36
35: ; preds = %16
tail call void @llvm.assume(i1 %3)
br label %41
36: ; preds = %22
%37 = load i8*, i8** %31
%38 = tail call i32 @perror(i8* %37)
br label %43
39: ; preds = %11, %5
%40 = tail call i32 @writes(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %43
41: ; preds = %35, %2, %21
%42 = tail call i32 @writes(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %22, %41, %39, %36
%44 = phi i32 [ 1, %41 ], [ 1, %39 ], [ 1, %36 ], [ 0, %22 ]
ret i32 %44
}