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

/* Variables and functions */
int S_IFCHR;
int find_major_no(char const *);
int /*<<< orphan*/ makedev(int, int const);
scalar_t__ mknod(char const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int stat(char const *, struct stat *);
int create_dev(const char *path, const char *name, const int minor) {
  struct stat sb;
  int result, major;
  result = stat(path, &sb);
  if (result < 0) {
    major = find_major_no(name);
    if (major < 0)
      return -1;
    if (mknod(path, 0600 | S_IFCHR, makedev(major, minor))) {
      perror("create_dev: Unable to create device");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11f8 <create_dev+0xa8>
mov    -0x18(%rbp),%rdi
call   1030 <find_major_no@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    119f <create_dev+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <create_dev+0xaf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
or     $0x180,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1070 <makedev@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
call   1050 <mknod@plt>
cmp    $0x0,%rax
je     11f3 <create_dev+0xa3>
lea    0xe1e(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <create_dev+0xaf>
jmp    11f8 <create_dev+0xa8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_dev>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1040 <stat@plt>
xor    %r15d,%r15d
test   %eax,%eax
jns    11b6 <create_dev+0x66>
mov    %rbp,%rdi
call   1030 <find_major_no@plt>
test   %eax,%eax
js     11b0 <create_dev+0x60>
mov    0x2e5e(%rip),%rcx
mov    $0x180,%ebp
or     (%rcx),%ebp
mov    %eax,%edi
mov    %r14d,%esi
call   1070 <makedev@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <mknod@plt>
test   %rax,%rax
je     11b6 <create_dev+0x66>
lea    0xe55(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFCHR = global i32 0
@.str = [36 x i8] c"create_dev: Unable to create device\00"
define i32 @create_dev(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = call i32 @stat(i8* %11, %struct.stat* %8)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = call i32 @find_major_no(i8* %16)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 -1, i32* %4
br label %34
21: ; preds = %15
%22 = load i8*, i8** %5
%23 = load i32, i32* @S_IFCHR
%24 = or i32 384, %23
%25 = load i32, i32* %10
%26 = load i32, i32* %7
%27 = call i32 @makedev(i32 %25, i32 %26)
%28 = call i64 @mknod(i8* %22, i32 %24, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %34
32: ; preds = %21
br label %33
33: ; preds = %32, %3
store i32 0, i32* %4
br label %34
34: ; preds = %33, %30, %20
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFCHR = global i32 0
@.str = [36 x i8] c"create_dev: Unable to create device\00"
define i32 @create_dev(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i32 @stat(i8* %0, %struct.stat* %4)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %3
%9 = tail call i32 @find_major_no(i8* %1)
%10 = icmp slt i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %8
%12 = load i32, i32* @S_IFCHR
%13 = or i32 %12, 384
%14 = tail call i32 @makedev(i32 %9, i32 %2)
%15 = tail call i64 @mknod(i8* %0, i32 %13, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %3, %11, %8, %17
%20 = phi i32 [ -1, %17 ], [ -1, %8 ], [ 0, %11 ], [ 0, %3 ]
ret i32 %20
}