#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 */

/* Variables and functions */
int S_IFBLK;
int S_IFCHR;
int atoi(char *);
scalar_t__ mknod(char const *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcmp(char const *, char *);
int main(int argc, char **argv) {
  if (argc == 5) {
    const char *name = *++argv;
    const char *type = *++argv;
    int major = atoi(*++argv);
    int minor = atoi(*++argv);
    int t = 0;
    if (!strcmp(type, "c")) {
      t = S_IFCHR;
    } else if (!strcmp(type, "b")) {
      t = S_IFBLK;
    }
    if (mknod(name, t, major << 8 | minor) < 0) {
      perror("mknod");
    }
  } else {
    printf("Wrong arguments number\n");
  }
}


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   $0x5,-0x8(%rbp)
jne    125f <main+0x10f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1205 <main+0xb5>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    122f <main+0xdf>
mov    -0x20(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    122a <main+0xda>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    122f <main+0xdf>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x24(%rbp),%edx
shl    $0x8,%edx
or     -0x28(%rbp),%edx
call   1050 <mknod@plt>
cmp    $0x0,%rax
jge    125a <main+0x10a>
lea    0xdaf(%rip),%rdi
call   1060 <perror@plt>
jmp    126b <main+0x11b>
lea    0xda4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x5,%edi
jne    11ae <main+0x5e>
mov    %rsi,%rbx
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%r15
mov    0x18(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    0x20(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
lea    0xe7c(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11bc <main+0x6c>
lea    0xe6b(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
xor    %esi,%esi
test   %eax,%eax
jne    11c5 <main+0x75>
mov    0x2e34(%rip),%rax
jmp    11c3 <main+0x73>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
jmp    11d9 <main+0x89>
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
shl    $0x8,%ebp
or     %ebp,%ebx
mov    %r14,%rdi
mov    %ebx,%edx
call   1050 <mknod@plt>
test   %rax,%rax
js     11e6 <main+0x96>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe17(%rip),%rdi
call   1060 <perror@plt>
jmp    11d9 <main+0x89>

LLVM IR (-O0):
@.str = [2 x i8] c"c\00"
@S_IFCHR = global i32 0
@.str.1 = [2 x i8] c"b\00"
@S_IFBLK = global i32 0
@.str.2 = [6 x i8] c"mknod\00"
@.str.3 = [24 x i8] c"Wrong arguments number\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%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 eq i32 %11, 5
br i1 %12, label %13, label %52
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i32 1
store i8** %15, i8*** %5
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i32 1
store i8** %18, i8*** %5
%19 = load i8*, i8** %18
store i8* %19, i8** %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i32 1
store i8** %21, i8*** %5
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i32 1
store i8** %25, i8*** %5
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %9
store i32 0, i32* %10
%28 = load i8*, i8** %7
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %13
%32 = load i32, i32* @S_IFCHR
store i32 %32, i32* %10
br label %40
33: ; preds = %13
%34 = load i8*, i8** %7
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = load i32, i32* @S_IFBLK
store i32 %38, i32* %10
br label %39
39: ; preds = %37, %33
br label %40
40: ; preds = %39, %31
%41 = load i8*, i8** %6
%42 = load i32, i32* %10
%43 = load i32, i32* %8
%44 = shl i32 %43, 8
%45 = load i32, i32* %9
%46 = or i32 %44, %45
%47 = call i64 @mknod(i8* %41, i32 %42, i32 %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %40
%50 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %49, %40
br label %54
52: ; preds = %2
%53 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %51
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [2 x i8] c"c\00"
@S_IFCHR = global i32 0
@.str.1 = [2 x i8] c"b\00"
@S_IFBLK = global i32 0
@.str.2 = [6 x i8] c"mknod\00"
@str = [23 x i8] c"Wrong arguments number\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %4, label %32
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 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 4
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* @S_IFCHR
br label %24
19: ; preds = %4
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
%22 = load i32, i32* @S_IFBLK
%23 = select i1 %21, i32 %22, i32 0
br label %24
24: ; preds = %19, %17
%25 = phi i32 [ %18, %17 ], [ %23, %19 ]
%26 = shl i32 %11, 8
%27 = or i32 %14, %26
%28 = tail call i64 @mknod(i8* %6, i32 %25, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %34
32: ; preds = %2
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %24, %30, %32
ret i32 0
}