#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 */
scalar_t__ ENOENT;
int S_IFCHR;
int S_IREAD;
int S_IWRITE;
scalar_t__ errno;
int /*<<< orphan*/ makedev(int, int);
int mknod(char *, int, int /*<<< orphan*/);
int stat(char *, struct stat *);
int mk_node(char *devname, int major, int minor) {
  struct stat statval;
  int retval;
  retval = stat(devname, &statval);
  if (retval == 0)
    return (0);
  else if (errno != ENOENT) {
    return -1;
  }
  return (mknod(devname, S_IFCHR | S_IREAD | S_IWRITE, makedev(major, minor)));
}


x86 assembly (clang, -O0):
<mk_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1168 <mk_node+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <mk_node+0xa5>
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    0x2e3f(%rip),%rcx
cmp    (%rcx),%rax
je     118e <mk_node+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <mk_node+0xa5>
jmp    1193 <mk_node+0x63>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    0x2e1d(%rip),%rcx
or     (%rcx),%eax
mov    0x2e34(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <makedev@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    %eax,%edx
call   1040 <mknod@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mk_node>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1030 <stat@plt>
test   %eax,%eax
je     11a3 <mk_node+0x73>
mov    0x2e7d(%rip),%rax
mov    (%rax),%rcx
mov    0x2e5b(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jne    11a5 <mk_node+0x75>
mov    0x2e6a(%rip),%rax
mov    0x2e53(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x2e68(%rip),%rax
or     (%rax),%ebp
mov    %r15d,%edi
mov    %r14d,%esi
call   1050 <makedev@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <mknod@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@S_IFCHR = global i32 0
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
define i32 @mk_node(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = call i32 @stat(i8* %10, %struct.stat* %8)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %32
15: ; preds = %3
%16 = load i64, i64* @errno
%17 = load i64, i64* @ENOENT
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %4
br label %32
20: ; preds = %15
br label %21
21: ; preds = %20
%22 = load i8*, i8** %5
%23 = load i32, i32* @S_IFCHR
%24 = load i32, i32* @S_IREAD
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IWRITE
%27 = or i32 %25, %26
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = call i32 @makedev(i32 %28, i32 %29)
%31 = call i32 @mknod(i8* %22, i32 %27, i32 %30)
store i32 %31, i32* %4
br label %32
32: ; preds = %21, %19, %14
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@S_IFCHR = global i32 0
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
define i32 @mk_node(i8* %0, i32 %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 eq i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %3
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i32, i32* @S_IFCHR
%14 = load i32, i32* @S_IREAD
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IWRITE
%17 = or i32 %15, %16
%18 = tail call i32 @makedev(i32 %1, i32 %2)
%19 = tail call i32 @mknod(i8* %0, i32 %17, i32 %18)
br label %20
20: ; preds = %8, %3, %12
%21 = phi i32 [ %19, %12 ], [ 0, %3 ], [ -1, %8 ]
ret i32 %21
}