#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 */
struct stat {
  int st_rdev;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int S_IFCHR;
scalar_t__ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int get_misc_minor();
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ mknod(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ pkt_dev_name(char *);
scalar_t__ stat(int /*<<< orphan*/, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unlink(int /*<<< orphan*/);
void create_ctl_dev(void) {
  int misc_minor;
  struct stat stat_buf;
  int dev;
  if ((misc_minor = get_misc_minor()) < 0) {
    system("/sbin/modprobe pktcdvd");
    misc_minor = get_misc_minor();
  }
  if (misc_minor < 0) {
    fprintf(stderr, "Can't find pktcdvd character device\n");
    return;
  }
  dev = ((misc_minor & 0xff) | (10 << 8) | ((misc_minor & ~0xff) << 12));
  if ((stat(pkt_dev_name("control"), &stat_buf) >= 0) &&
      S_ISCHR(stat_buf.st_mode) && (stat_buf.st_rdev == dev))
    return;
  mkdir("/dev/pktcdvd", 0755);
  unlink(pkt_dev_name("control"));
  mknod(pkt_dev_name("control"), S_IFCHR | 0644, dev);
}


x86 assembly (clang, -O0):
<create_ctl_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   10b0 <get_misc_minor@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11c1 <create_ctl_dev+0x31>
lea    0xe4e(%rip),%rdi
call   1050 <system@plt>
mov    $0x0,%al
call   10b0 <get_misc_minor@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11e5 <create_ctl_dev+0x55>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1290 <create_ctl_dev+0x100>
mov    -0x4(%rbp),%eax
and    $0xff,%eax
or     $0xa00,%eax
mov    -0x4(%rbp),%ecx
and    $0xffffff00,%ecx
shl    $0xc,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
lea    0xe32(%rip),%rdi
call   10a0 <pkt_dev_name@plt>
mov    %eax,%edi
lea    -0x10(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jl     1247 <create_ctl_dev+0xb7>
mov    -0xc(%rbp),%edi
call   1090 <S_ISCHR@plt>
cmp    $0x0,%rax
je     1247 <create_ctl_dev+0xb7>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1247 <create_ctl_dev+0xb7>
jmp    1290 <create_ctl_dev+0x100>
lea    0xdf6(%rip),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
lea    0xddd(%rip),%rdi
call   10a0 <pkt_dev_name@plt>
mov    %eax,%edi
call   1030 <unlink@plt>
lea    0xdca(%rip),%rdi
call   10a0 <pkt_dev_name@plt>
mov    %eax,%edi
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
or     $0x1a4,%esi
mov    -0x14(%rbp),%edx
call   1080 <mknod@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_ctl_dev>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   10b0 <get_misc_minor@plt>
test   %eax,%eax
jns    11b9 <create_ctl_dev+0x29>
lea    0xe5b(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
call   10b0 <get_misc_minor@plt>
test   %eax,%eax
js     1248 <create_ctl_dev+0xb8>
movzbl %al,%ecx
shl    $0xc,%eax
and    $0xfff00000,%eax
lea    (%rcx,%rax,1),%ebp
add    $0xa00,%ebp
lea    0xe68(%rip),%rdi
call   10a0 <pkt_dev_name@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1070 <stat@plt>
test   %rax,%rax
js     11fb <create_ctl_dev+0x6b>
mov    0x4(%rsp),%edi
call   1090 <S_ISCHR@plt>
test   %rax,%rax
je     11fb <create_ctl_dev+0x6b>
cmp    %ebp,(%rsp)
je     1241 <create_ctl_dev+0xb1>
lea    0xe42(%rip),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
lea    0xe29(%rip),%rbx
mov    %rbx,%rdi
call   10a0 <pkt_dev_name@plt>
mov    %eax,%edi
call   1030 <unlink@plt>
mov    %rbx,%rdi
call   10a0 <pkt_dev_name@plt>
mov    0x2da7(%rip),%rcx
mov    $0x1a4,%esi
or     (%rcx),%esi
mov    %eax,%edi
mov    %ebp,%edx
call   1080 <mknod@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [23 x i8] c"/sbin/modprobe pktcdvd\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"Can't find pktcdvd character device\0A\00"
@.str.2 = [8 x i8] c"control\00"
@.str.3 = [13 x i8] c"/dev/pktcdvd\00"
@S_IFCHR = global i32 0
define void @create_ctl_dev() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i32
%4 = call i32 (...) @get_misc_minor()
store i32 %4, i32* %1
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @get_misc_minor()
store i32 %8, i32* %1
br label %9
9: ; preds = %6, %0
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %46
15: ; preds = %9
%16 = load i32, i32* %1
%17 = and i32 %16, 255
%18 = or i32 %17, 2560
%19 = load i32, i32* %1
%20 = and i32 %19, -256
%21 = shl i32 %20, 12
%22 = or i32 %18, %21
store i32 %22, i32* %3
%23 = call i32 @pkt_dev_name(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%24 = call i64 @stat(i32 %23, %struct.stat* %2)
%25 = icmp sge i64 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %15
%27 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%28 = load i32, i32* %27
%29 = call i64 @S_ISCHR(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%33 = load i32, i32* %32
%34 = load i32, i32* %3
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %31
br label %46
37: ; preds = %31, %26, %15
%38 = call i32 @mkdir(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 493)
%39 = call i32 @pkt_dev_name(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @unlink(i32 %39)
%41 = call i32 @pkt_dev_name(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @S_IFCHR
%43 = or i32 %42, 420
%44 = load i32, i32* %3
%45 = call i32 @mknod(i32 %41, i32 %43, i32 %44)
br label %46
46: ; preds = %37, %36, %12
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [23 x i8] c"/sbin/modprobe pktcdvd\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"Can't find pktcdvd character device\0A\00"
@.str.2 = [8 x i8] c"control\00"
@.str.3 = [13 x i8] c"/dev/pktcdvd\00"
@S_IFCHR = global i32 0
define void @create_ctl_dev() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i32 (...) @get_misc_minor()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = tail call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @get_misc_minor()
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %39
12: ; preds = %0, %5
%13 = phi i32 [ %7, %5 ], [ %3, %0 ]
%14 = and i32 %13, 255
%15 = shl i32 %13, 12
%16 = and i32 %15, -1048576
%17 = or i32 %14, %16
%18 = or i32 %17, 2560
%19 = tail call i32 @pkt_dev_name(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%20 = call i64 @stat(i32 %19, %struct.stat* %1)
%21 = icmp sgt i64 %20, -1
br i1 %21, label %22, label %31
22: ; preds = %12
%23 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%24 = load i32, i32* %23
%25 = call i64 @S_ISCHR(i32 %24)
%26 = icmp ne i64 %25, 0
%27 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, %18
%30 = select i1 %26, i1 %29, i1 false
br i1 %30, label %39, label %31
31: ; preds = %22, %12
%32 = call i32 @mkdir(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 493)
%33 = call i32 @pkt_dev_name(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @unlink(i32 %33)
%35 = call i32 @pkt_dev_name(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @S_IFCHR
%37 = or i32 %36, 420
%38 = call i32 @mknod(i32 %35, i32 %37, i32 %18)
br label %39
39: ; preds = %22, %31, %9
ret void
}