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

/* Variables and functions */
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int handle_zng(int);
int mknod(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int mknod_test(char *path, mode_t mode, dev_t dev) {
  int ret, save_errno;
  int passed;
  printf("mknod(): path=%s, mode=0x%x(0%o), dev=%ld\n",
         (((path) == NULL) ? "(null)" : (path)), mode, mode, dev);
  fflush(NULL);
  passed = handle_zng(ret = mknod(path, mode, dev));
  save_errno = errno;
  switch (passed) {
  case -1:
  case 0:
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = %d\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<mknod_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116d <mknod_test+0x2d>
lea    0xec7(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1175 <mknod_test+0x35>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xe79(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x30(%rbp)
mov    %ecx,%edx
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,%edi
call   1060 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <mknod@plt>
mov    %eax,%edi
mov    %edi,-0x14(%rbp)
call   1030 <handle_zng@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xfffffffe,%eax
je     121a <mknod_test+0xda>
jmp    11d9 <mknod_test+0x99>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
ja     1239 <mknod_test+0xf9>
jmp    11ed <mknod_test+0xad>
mov    -0x14(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
jmp    1253 <mknod_test+0x113>
mov    -0x14(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
jmp    1253 <mknod_test+0x113>
mov    -0x1c(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
mov    -0x18(%rbp),%ecx
mov    0x2d83(%rip),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mknod_test>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0xec5(%rip),%rsi
cmovne %rdi,%rsi
lea    0xe8f(%rip),%rdi
mov    %ebp,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1060 <mknod@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <handle_zng@plt>
mov    0x2e3d(%rip),%r14
mov    (%r14),%ebp
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jae    11cc <mknod_test+0x7c>
lea    0xe7d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed9(%rip),%rdi
call   1030 <puts@plt>
jmp    11ec <mknod_test+0x9c>
cmp    $0xfffffffe,%eax
jne    11dc <mknod_test+0x8c>
lea    0xe66(%rip),%rdi
mov    %ebx,%esi
jmp    11e5 <mknod_test+0x95>
lea    0xe90(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
mov    %ebp,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"mknod(): path=%s, mode=0x%x(0%o), dev=%ld\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.3 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @mknod_test(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
br label %15
13: ; preds = %3
%14 = load i8*, i8** %4
br label %15
15: ; preds = %13, %12
%16 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %12 ], [ %14, %13 ]
%17 = load i32, i32* %5
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17, i32 %18, i32 %19)
%21 = call i32 @fflush(i32* null)
%22 = load i8*, i8** %4
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = call i32 @mknod(i8* %22, i32 %23, i32 %24)
store i32 %25, i32* %7
%26 = call i32 @handle_zng(i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* @errno
store i32 %27, i32* %8
%28 = load i32, i32* %9
switch i32 %28, label %38 [
i32 -1, label %29
i32 0, label %29
i32 -2, label %34
]
29: ; preds = %15, %15
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @fflush(i32* null)
br label %42
34: ; preds = %15
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = call i32 @fflush(i32* null)
br label %42
38: ; preds = %15
%39 = load i32, i32* %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = call i32 @fflush(i32* null)
br label %42
42: ; preds = %38, %34, %29
%43 = load i32, i32* %8
store i32 %43, i32* @errno
%44 = load i32, i32* %7
ret i32 %44
}

LLVM IR (-O2):
@.str = [43 x i8] c"mknod(): path=%s, mode=0x%x(0%o), dev=%ld\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @mknod_test(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i8* %0, null
%5 = select i1 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %1, i32 %1, i32 %2)
%7 = tail call i32 @fflush(i32* null)
%8 = tail call i32 @mknod(i8* %0, i32 %1, i32 %2)
%9 = tail call i32 @handle_zng(i32 %8)
%10 = load i32, i32* @errno
switch i32 %9, label %16 [
i32 -1, label %11
i32 0, label %11
i32 -2, label %14
]
11: ; preds = %3, %3
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %18
14: ; preds = %3
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %8)
br label %18
16: ; preds = %3
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %9)
br label %18
18: ; preds = %16, %14, %11
%19 = tail call i32 @fflush(i32* null)
store i32 %10, i32* @errno
ret i32 %8
}