#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 mode_t;
typedef int /*<<< orphan*/ dev_t;

/* Variables and functions */
int S_IFBLK;
int S_IFCHR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int atoi(char *);
int /*<<< orphan*/ makedev(int, int);
scalar_t__ mknod(char *, int, int /*<<< orphan*/);
int nod_type(char *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  if (argc < 3)
    return 1;
  char *path = argv[1];
  mode_t mode = nod_type(argv[2]);
  dev_t dev = 0;
  if (mode == S_IFCHR || mode == S_IFBLK) {
    if (argc < 5)
      return 1;
    int maj = 0, min = 0;
    maj = atoi(argv[3]);
    min = atoi(argv[4]);
    dev = makedev(maj, min);
  }
  if (mknod(path,
            (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) | mode,
            dev) < 0) {
    perror("mknod");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    117c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    1283 <main+0x133>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <nod_type@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%eax
je     11c3 <main+0x73>
mov    -0x1c(%rbp),%eax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%eax
jne    1215 <main+0xc5>
cmpl   $0x5,-0x8(%rbp)
jge    11d9 <main+0x89>
movl   $0x1,-0x4(%rbp)
jmp    1283 <main+0x133>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1060 <makedev@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    0x2db7(%rip),%rax
or     (%rax),%esi
mov    0x2d8e(%rip),%rax
or     (%rax),%esi
mov    0x2dad(%rip),%rax
or     (%rax),%esi
mov    0x2d74(%rip),%rax
or     (%rax),%esi
mov    0x2d53(%rip),%rax
or     (%rax),%esi
or     -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <mknod@plt>
cmp    $0x0,%rax
jge    127c <main+0x12c>
lea    0xd95(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1283 <main+0x133>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%r15d
cmp    $0x3,%edi
jl     1202 <main+0xb2>
mov    %rsi,%r12
mov    %edi,%ebx
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
call   1030 <nod_type@plt>
mov    %eax,%ebp
mov    0x2e46(%rip),%rax
cmp    (%rax),%ebp
je     1193 <main+0x43>
xor    %edx,%edx
mov    0x2e41(%rip),%rax
cmp    (%rax),%ebp
jne    11b9 <main+0x69>
cmp    $0x5,%ebx
jb     1202 <main+0xb2>
mov    0x18(%r12),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
mov    0x20(%r12),%rdi
call   1070 <atoi@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <makedev@plt>
mov    %eax,%edx
mov    0x2df0(%rip),%rax
mov    0x2e19(%rip),%rcx
mov    0x2df2(%rip),%rsi
mov    0x2e13(%rip),%rdi
mov    0x2ddc(%rip),%rbx
mov    0x2dbd(%rip),%r8
or     (%rax),%ebp
or     (%rcx),%ebp
or     (%rsi),%ebp
or     (%rdi),%ebp
or     (%rbx),%ebp
or     (%r8),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <mknod@plt>
xor    %r15d,%r15d
test   %rax,%rax
js     120e <main+0xbe>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdeb(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%r15d
jmp    1202 <main+0xb2>

LLVM IR (-O0):
@S_IFCHR = global i32 0
@S_IFBLK = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str = [6 x i8] c"mknod\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 i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %66
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @nod_type(i8* %20)
store i32 %21, i32* %7
store i32 0, i32* %8
%22 = load i32, i32* %7
%23 = load i32, i32* @S_IFCHR
%24 = icmp eq i32 %22, %23
br i1 %24, label %29, label %25
25: ; preds = %14
%26 = load i32, i32* %7
%27 = load i32, i32* @S_IFBLK
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %45
29: ; preds = %25, %14
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 5
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 1, i32* %3
br label %66
33: ; preds = %29
store i32 0, i32* %9
store i32 0, i32* %10
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %9
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 4
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %10
%42 = load i32, i32* %9
%43 = load i32, i32* %10
%44 = call i32 @makedev(i32 %42, i32 %43)
store i32 %44, i32* %8
br label %45
45: ; preds = %33, %25
%46 = load i8*, i8** %6
%47 = load i32, i32* @S_IRUSR
%48 = load i32, i32* @S_IWUSR
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IRGRP
%51 = or i32 %49, %50
%52 = load i32, i32* @S_IWGRP
%53 = or i32 %51, %52
%54 = load i32, i32* @S_IROTH
%55 = or i32 %53, %54
%56 = load i32, i32* @S_IWOTH
%57 = or i32 %55, %56
%58 = load i32, i32* %7
%59 = or i32 %57, %58
%60 = load i32, i32* %8
%61 = call i64 @mknod(i8* %46, i32 %59, i32 %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %45
%64 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %66
65: ; preds = %45
store i32 0, i32* %3
br label %66
66: ; preds = %65, %63, %32, %13
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@S_IFCHR = global i32 0
@S_IFBLK = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str = [6 x i8] c"mknod\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %43, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 @nod_type(i8* %8)
%10 = load i32, i32* @S_IFCHR
%11 = icmp eq i32 %9, %10
%12 = load i32, i32* @S_IFBLK
%13 = icmp eq i32 %9, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %25
15: ; preds = %4
%16 = icmp ult i32 %0, 5
br i1 %16, label %43, label %17
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 4
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = tail call i32 @makedev(i32 %20, i32 %23)
br label %25
25: ; preds = %4, %17
%26 = phi i32 [ %24, %17 ], [ 0, %4 ]
%27 = load i32, i32* @S_IRUSR
%28 = load i32, i32* @S_IWUSR
%29 = load i32, i32* @S_IRGRP
%30 = load i32, i32* @S_IWGRP
%31 = load i32, i32* @S_IROTH
%32 = load i32, i32* @S_IWOTH
%33 = or i32 %27, %9
%34 = or i32 %33, %28
%35 = or i32 %34, %29
%36 = or i32 %35, %30
%37 = or i32 %36, %31
%38 = or i32 %37, %32
%39 = tail call i64 @mknod(i8* %6, i32 %38, i32 %26)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %25
%42 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %41, %15, %25, %2
%44 = phi i32 [ 1, %2 ], [ 1, %41 ], [ 1, %15 ], [ 0, %25 ]
ret i32 %44
}