#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 /*<<< orphan*/ S_ISDEV(int);
int /*<<< orphan*/ S_ISFIFO(int);
scalar_t__ mknod(char *, int, int);
int parse_number(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ writes(char *);
int do_mknod(char *path, char *modes, char *devs) {
  int mode;
  int dev;
  mode = parse_number(modes, 8);
  if (mode < 0) {
    writes("mknod: bad mode\n");
    return 1;
  }
  if (!S_ISFIFO(mode) && !S_ISDEV(mode)) {
    writes("mknod: mode is not device/fifo\n");
    return 1;
  }
  dev = parse_number(devs, 10);
  if (dev < 0) {
    writes("mknod: bad device\n");
    return 1;
  }
  if (mknod(path, mode, dev) != 0) {
    perror("mknod");
    return 1;
  }
  return (0);
}


x86 assembly (clang, -O0):
<do_mknod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1080 <parse_number@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a7 <do_mknod+0x47>
lea    0xe6a(%rip),%rdi
call   1040 <writes@plt>
movl   $0x1,-0x4(%rbp)
jmp    124c <do_mknod+0xec>
mov    -0x24(%rbp),%edi
call   1030 <S_ISFIFO@plt>
cmp    $0x0,%eax
jne    11e1 <do_mknod+0x81>
mov    -0x24(%rbp),%edi
call   1060 <S_ISDEV@plt>
cmp    $0x0,%eax
jne    11e1 <do_mknod+0x81>
lea    0xe41(%rip),%rdi
call   1040 <writes@plt>
movl   $0x1,-0x4(%rbp)
jmp    124c <do_mknod+0xec>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1080 <parse_number@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1214 <do_mknod+0xb4>
lea    0xe2e(%rip),%rdi
call   1040 <writes@plt>
movl   $0x1,-0x4(%rbp)
jmp    124c <do_mknod+0xec>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1050 <mknod@plt>
cmp    $0x0,%rax
je     1245 <do_mknod+0xe5>
lea    0xe10(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    124c <do_mknod+0xec>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_mknod>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x8,%esi
call   1080 <parse_number@plt>
test   %eax,%eax
js     11c8 <do_mknod+0x68>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <S_ISFIFO@plt>
test   %eax,%eax
jne    1193 <do_mknod+0x33>
mov    %ebp,%edi
call   1060 <S_ISDEV@plt>
test   %eax,%eax
je     11da <do_mknod+0x7a>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1080 <parse_number@plt>
test   %eax,%eax
js     11d1 <do_mknod+0x71>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <mknod@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     11eb <do_mknod+0x8b>
lea    0xe83(%rip),%rdi
call   1070 <perror@plt>
jmp    11e6 <do_mknod+0x86>
lea    0xe31(%rip),%rdi
jmp    11e1 <do_mknod+0x81>
lea    0xe59(%rip),%rdi
jmp    11e1 <do_mknod+0x81>
lea    0xe30(%rip),%rdi
call   1040 <writes@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"mknod: bad mode\0A\00"
@.str.1 = [32 x i8] c"mknod: mode is not device/fifo\0A\00"
@.str.2 = [19 x i8] c"mknod: bad device\0A\00"
@.str.3 = [6 x i8] c"mknod\00"
define i32 @do_mknod(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %6
%11 = call i32 @parse_number(i8* %10, i32 8)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @writes(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %42
16: ; preds = %3
%17 = load i32, i32* %8
%18 = call i32 @S_ISFIFO(i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %16
%21 = load i32, i32* %8
%22 = call i32 @S_ISDEV(i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 @writes(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %42
26: ; preds = %20, %16
%27 = load i8*, i8** %7
%28 = call i32 @parse_number(i8* %27, i32 10)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @writes(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %42
33: ; preds = %26
%34 = load i8*, i8** %5
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%37 = call i64 @mknod(i8* %34, i32 %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %4
br label %42
41: ; preds = %33
store i32 0, i32* %4
br label %42
42: ; preds = %41, %39, %31, %24, %14
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@.str = [17 x i8] c"mknod: bad mode\0A\00"
@.str.1 = [32 x i8] c"mknod: mode is not device/fifo\0A\00"
@.str.2 = [19 x i8] c"mknod: bad device\0A\00"
@.str.3 = [6 x i8] c"mknod\00"
define i32 @do_mknod(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @parse_number(i8* %1, i32 8)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @writes(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %26
8: ; preds = %3
%9 = tail call i32 @S_ISFIFO(i32 %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = tail call i32 @S_ISDEV(i32 %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @writes(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %26
16: ; preds = %11, %8
%17 = tail call i32 @parse_number(i8* %2, i32 10)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @writes(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %26
21: ; preds = %16
%22 = tail call i64 @mknod(i8* %0, i32 %4, i32 %17)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %21, %24, %19, %14, %6
%27 = phi i32 [ 1, %6 ], [ 1, %19 ], [ 1, %24 ], [ 1, %14 ], [ 0, %21 ]
ret i32 %27
}