#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 /*<<< orphan*/ dev_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int S_IFCHR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ makedev(int, int /*<<< orphan*/);
scalar_t__ mknod(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ say(int /*<<< orphan*/, char *, char *, int);
int strerror(int /*<<< orphan*/);
int makechardev() {
  dev_t dev = makedev(100, 0);
  if (mknod("/dev/gpu_mb", S_IFCHR | 0644, dev) != 0) {
    say(LOG_ERR, "Can't create character device: %s - '%s'\n", "/dev/gpu_mb",
        strerror(errno));
    say(LOG_INFO,
        "Try manually creating a device file with: sudo mknod %s c %d 0\n",
        "/dev/gpu_mb", 100);
    return -1;
  };
  return 0;
}


x86 assembly (clang, -O0):
<makechardev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x64,%edi
xor    %esi,%esi
call   1040 <makedev@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
or     $0x1a4,%esi
mov    -0x8(%rbp),%edx
lea    0xe90(%rip),%rdi
call   1030 <mknod@plt>
cmp    $0x0,%rax
je     11de <makechardev+0x9e>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%ecx
lea    0xe67(%rip),%rsi
lea    0xe54(%rip),%rdx
call   1060 <say@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
lea    0xe38(%rip),%rdx
mov    $0x64,%ecx
call   1060 <say@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <makechardev+0xa5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makechardev>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
mov    $0x64,%edi
xor    %esi,%esi
call   1040 <makedev@plt>
mov    0x2e87(%rip),%rcx
mov    $0x1a4,%esi
or     (%rcx),%esi
lea    0xe99(%rip),%rdi
mov    %eax,%edx
call   1030 <mknod@plt>
test   %rax,%rax
je     11c6 <makechardev+0x86>
mov    0x2e46(%rip),%rax
mov    (%rax),%ebx
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7b(%rip),%rsi
lea    0xe68(%rip),%r14
mov    %ebx,%edi
mov    %r14,%rdx
mov    %eax,%ecx
call   1060 <say@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %r14,%rdx
mov    $0x64,%ecx
call   1060 <say@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/gpu_mb\00"
@S_IFCHR = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [42 x i8] c"Can't create character device: %s - '%s'\0A\00"
@errno = global i32 0
@LOG_INFO = global i32 0
@.str.2 = [64 x i8] c"Try manually creating a device file with: sudo mknod %s c %d 0\0A\00"
define i32 @makechardev() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @makedev(i32 100, i32 0)
store i32 %3, i32* %2
%4 = load i32, i32* @S_IFCHR
%5 = or i32 %4, 420
%6 = load i32, i32* %2
%7 = call i64 @mknod(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = load i32, i32* @LOG_ERR
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 @say(i32 %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @LOG_INFO
%15 = call i32 @say(i32 %14, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 100)
store i32 -1, i32* %1
br label %17
16: ; preds = %0
store i32 0, i32* %1
br label %17
17: ; preds = %16, %9
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/gpu_mb\00"
@S_IFCHR = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [42 x i8] c"Can't create character device: %s - '%s'\0A\00"
@errno = global i32 0
@LOG_INFO = global i32 0
@.str.2 = [64 x i8] c"Try manually creating a device file with: sudo mknod %s c %d 0\0A\00"
define i32 @makechardev() {
%1 = tail call i32 @makedev(i32 100, i32 0)
%2 = load i32, i32* @S_IFCHR
%3 = or i32 %2, 420
%4 = tail call i64 @mknod(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %0
%7 = load i32, i32* @LOG_ERR
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @say(i32 %7, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @LOG_INFO
%12 = tail call i32 @say(i32 %11, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 100)
br label %13
13: ; preds = %0, %6
%14 = phi i32 [ -1, %6 ], [ 0, %0 ]
ret i32 %14
}