#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;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ O_RDWR;
int S_IFCHR;
scalar_t__ access(char *const, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int /*<<< orphan*/);
int /*<<< orphan*/ exec_init(char **, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ makedev(int, int);
int /*<<< orphan*/ mknod(char *const, int, int /*<<< orphan*/);
int open(char *const, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int umask(int);
int main(int argc, char **argv, char **envp) {
  char *const console_dev = "/dev/console";
  char *const null_dev = "/dev/null";
  char *const ttyAS0_dev = "/dev/ttyAS0";
  char *const vfd_dev = "/dev/vfd";
  if (getpid() == 1) {
    int fh;
    mode_t old = umask(0000);
    if (access(console_dev, F_OK)) {
      mknod(console_dev, S_IFCHR | 0600, makedev(5, 1));
      fh = open(console_dev, O_RDWR);
      if (fh) {
        close(fh);
      } else {
        dup(0);
        dup(0);
      }
    }
    if (access(null_dev, F_OK))
      mknod(null_dev, S_IFCHR | 0666, makedev(1, 3));
    if (access(ttyAS0_dev, F_OK))
      mknod(ttyAS0_dev, S_IFCHR | 0660, makedev(204, 40));
    if (access(vfd_dev, F_OK))
      mknod(vfd_dev, S_IFCHR | 0660, makedev(147, 0));
    umask(old);
    exec_init(argv, envp);
  } else {
    fprintf(stderr, "This program is supposed to be run by the kernel.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe3f(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe41(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe40(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe41(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
cmp    $0x1,%eax
jne    1399 <main+0x1f9>
xor    %edi,%edi
call   1080 <umask@plt>
mov    %eax,-0x40(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
lea    0xdf0(%rip),%rdi
call   10b0 <access@plt>
cmp    $0x0,%rax
je     1292 <main+0xf2>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
or     $0x180,%eax
mov    %eax,-0x44(%rbp)
mov    $0x5,%edi
mov    $0x1,%esi
call   10c0 <makedev@plt>
mov    -0x44(%rbp),%esi
mov    %eax,%edx
lea    0xdb5(%rip),%rdi
call   1090 <mknod@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
lea    0xda0(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     127f <main+0xdf>
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
jmp    128d <main+0xed>
xor    %edi,%edi
call   1050 <dup@plt>
xor    %edi,%edi
call   1050 <dup@plt>
jmp    1292 <main+0xf2>
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
lea    0xd6b(%rip),%rdi
call   10b0 <access@plt>
cmp    $0x0,%rax
je     12e2 <main+0x142>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
or     $0x1b6,%eax
mov    %eax,-0x48(%rbp)
mov    $0x1,%edi
mov    $0x3,%esi
call   10c0 <makedev@plt>
mov    -0x48(%rbp),%esi
mov    %eax,%edx
lea    0xd30(%rip),%rdi
call   1090 <mknod@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%esi
lea    0xd25(%rip),%rdi
call   10b0 <access@plt>
cmp    $0x0,%rax
je     1332 <main+0x192>
mov    0x2cc8(%rip),%rax
mov    (%rax),%eax
or     $0x1b0,%eax
mov    %eax,-0x4c(%rbp)
mov    $0xcc,%edi
mov    $0x28,%esi
call   10c0 <makedev@plt>
mov    -0x4c(%rbp),%esi
mov    %eax,%edx
lea    0xcea(%rip),%rdi
call   1090 <mknod@plt>
mov    0x2c87(%rip),%rax
mov    (%rax),%esi
lea    0xce1(%rip),%rdi
call   10b0 <access@plt>
cmp    $0x0,%rax
je     137f <main+0x1df>
mov    0x2c78(%rip),%rax
mov    (%rax),%eax
or     $0x1b0,%eax
mov    %eax,-0x50(%rbp)
mov    $0x93,%edi
xor    %esi,%esi
call   10c0 <makedev@plt>
mov    -0x50(%rbp),%esi
mov    %eax,%edx
lea    0xca9(%rip),%rdi
call   1090 <mknod@plt>
mov    -0x40(%rbp),%edi
call   1080 <umask@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <exec_init@plt>
jmp    13ae <main+0x20e>
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
lea    0xc83(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    $0x1,%eax
jne    1231 <main+0x91>
xor    %edi,%edi
call   1080 <umask@plt>
mov    %eax,%r15d
mov    0x2df2(%rip),%r13
mov    0x0(%r13),%esi
lea    0xe27(%rip),%rdi
call   10b0 <access@plt>
test   %rax,%rax
je     1259 <main+0xb9>
mov    0x2de6(%rip),%rax
mov    $0x180,%ebp
or     (%rax),%ebp
mov    $0x5,%edi
mov    $0x1,%esi
call   10c0 <makedev@plt>
lea    0xdf9(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1090 <mknod@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
test   %eax,%eax
je     124b <main+0xab>
mov    %eax,%edi
call   1060 <close@plt>
jmp    1259 <main+0xb9>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   1070 <fprintf@plt>
jmp    132f <main+0x18f>
xor    %edi,%edi
call   1050 <dup@plt>
xor    %edi,%edi
call   1050 <dup@plt>
mov    0x0(%r13),%esi
lea    0xda9(%rip),%rdi
call   10b0 <access@plt>
test   %rax,%rax
je     129b <main+0xfb>
mov    0x2d5b(%rip),%rax
mov    $0x1b6,%ebx
or     (%rax),%ebx
mov    $0x1,%edi
mov    $0x3,%esi
call   10c0 <makedev@plt>
lea    0xd7b(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1090 <mknod@plt>
mov    0x0(%r13),%esi
lea    0xd71(%rip),%rdi
call   10b0 <access@plt>
test   %rax,%rax
je     12dd <main+0x13d>
mov    0x2d19(%rip),%rax
mov    $0x1b0,%ebx
or     (%rax),%ebx
mov    $0xcc,%edi
mov    $0x28,%esi
call   10c0 <makedev@plt>
lea    0xd43(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1090 <mknod@plt>
mov    0x0(%r13),%esi
lea    0xd3b(%rip),%rdi
call   10b0 <access@plt>
test   %rax,%rax
je     131c <main+0x17c>
mov    0x2cd7(%rip),%rax
mov    $0x1b0,%ebx
or     (%rax),%ebx
mov    $0x93,%edi
xor    %esi,%esi
call   10c0 <makedev@plt>
lea    0xd10(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1090 <mknod@plt>
mov    %r15d,%edi
call   1080 <umask@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <exec_init@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/console\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@.str.2 = [12 x i8] c"/dev/ttyAS0\00"
@.str.3 = [9 x i8] c"/dev/vfd\00"
@F_OK = global i32 0
@S_IFCHR = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.4 = [51 x i8] c"This program is supposed to be run by the kernel.\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %11
%14 = call i32 (...) @getpid()
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %70
16: ; preds = %3
%17 = call i32 @umask(i32 0)
store i32 %17, i32* %13
%18 = load i32, i32* @F_OK
%19 = call i64 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %16
%22 = load i32, i32* @S_IFCHR
%23 = or i32 %22, 384
%24 = call i32 @makedev(i32 5, i32 1)
%25 = call i32 @mknod(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), i32 %23, i32 %24)
%26 = load i32, i32* @O_RDWR
%27 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), i32 %26)
store i32 %27, i32* %12
%28 = load i32, i32* %12
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = load i32, i32* %12
%32 = call i32 @close(i32 %31)
br label %36
33: ; preds = %21
%34 = call i32 @dup(i32 0)
%35 = call i32 @dup(i32 0)
br label %36
36: ; preds = %33, %30
br label %37
37: ; preds = %36, %16
%38 = load i32, i32* @F_OK
%39 = call i64 @access(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i32, i32* @S_IFCHR
%43 = or i32 %42, 438
%44 = call i32 @makedev(i32 1, i32 3)
%45 = call i32 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i32 %43, i32 %44)
br label %46
46: ; preds = %41, %37
%47 = load i32, i32* @F_OK
%48 = call i64 @access(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %46
%51 = load i32, i32* @S_IFCHR
%52 = or i32 %51, 432
%53 = call i32 @makedev(i32 204, i32 40)
%54 = call i32 @mknod(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i32 %52, i32 %53)
br label %55
55: ; preds = %50, %46
%56 = load i32, i32* @F_OK
%57 = call i64 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %55
%60 = load i32, i32* @S_IFCHR
%61 = or i32 %60, 432
%62 = call i32 @makedev(i32 147, i32 0)
%63 = call i32 @mknod(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i32 %61, i32 %62)
br label %64
64: ; preds = %59, %55
%65 = load i32, i32* %13
%66 = call i32 @umask(i32 %65)
%67 = load i8**, i8*** %6
%68 = load i8**, i8*** %7
%69 = call i32 @exec_init(i8** %67, i8** %68)
br label %73
70: ; preds = %3
%71 = load i32, i32* @stderr
%72 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
br label %73
73: ; preds = %70, %64
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/console\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@.str.2 = [12 x i8] c"/dev/ttyAS0\00"
@.str.3 = [9 x i8] c"/dev/vfd\00"
@F_OK = global i32 0
@S_IFCHR = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.4 = [51 x i8] c"This program is supposed to be run by the kernel.\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = tail call i32 (...) @getpid()
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %54
6: ; preds = %3
%7 = tail call i32 @umask(i32 0)
%8 = load i32, i32* @F_OK
%9 = tail call i64 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %6
%12 = load i32, i32* @S_IFCHR
%13 = or i32 %12, 384
%14 = tail call i32 @makedev(i32 5, i32 1)
%15 = tail call i32 @mknod(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* @O_RDWR
%17 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %11
%20 = tail call i32 @close(i32 %17)
br label %24
21: ; preds = %11
%22 = tail call i32 @dup(i32 0)
%23 = tail call i32 @dup(i32 0)
br label %24
24: ; preds = %19, %21, %6
%25 = load i32, i32* @F_OK
%26 = tail call i64 @access(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = load i32, i32* @S_IFCHR
%30 = or i32 %29, 438
%31 = tail call i32 @makedev(i32 1, i32 3)
%32 = tail call i32 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %31)
br label %33
33: ; preds = %28, %24
%34 = load i32, i32* @F_OK
%35 = tail call i64 @access(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %33
%38 = load i32, i32* @S_IFCHR
%39 = or i32 %38, 432
%40 = tail call i32 @makedev(i32 204, i32 40)
%41 = tail call i32 @mknod(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %39, i32 %40)
br label %42
42: ; preds = %37, %33
%43 = load i32, i32* @F_OK
%44 = tail call i64 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %42
%47 = load i32, i32* @S_IFCHR
%48 = or i32 %47, 432
%49 = tail call i32 @makedev(i32 147, i32 0)
%50 = tail call i32 @mknod(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %48, i32 %49)
br label %51
51: ; preds = %46, %42
%52 = tail call i32 @umask(i32 %7)
%53 = tail call i32 @exec_init(i8** %1, i8** %2)
br label %57
54: ; preds = %3
%55 = load i32, i32* @stderr
%56 = tail call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %54, %51
ret i32 0
}