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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ S_IFBLK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ makedev(unsigned int, unsigned int);
scalar_t__ mknod(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ util_path_exists(char *);
int create_temp_device_node(char *name, unsigned int major,
                            unsigned int minor) {
  const char path_base[] = "/dev";
  char buf[PATH_MAX];
  int n;
  for (n = 0; n < 100; n++) {
    snprintf(buf, sizeof(buf), "%s/zipl-dm-temp-%02d", path_base, n);
    if (util_path_exists(buf))
      continue;
    if (mknod(buf, S_IFBLK, makedev(major, minor)) != 0)
      continue;
    strcpy(name, buf);
    return 0;
  }
  fprintf(stderr,
          "Error: "
          "Could not create temporary device node in '%s'\n",
          path_base);
  return -1;
}


x86 assembly (clang, -O0):
<create_temp_device_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movb   $0x0,-0x1c(%rbp)
movl   $0x7665642f,-0x20(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x64,-0x34(%rbp)
jge    1256 <create_temp_device_node+0xf6>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%esi
lea    -0x20(%rbp),%rcx
mov    -0x34(%rbp),%r8d
lea    0xe2e(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rdi
call   1080 <util_path_exists@plt>
cmp    $0x0,%rax
je     11f4 <create_temp_device_node+0x94>
jmp    1248 <create_temp_device_node+0xe8>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1070 <makedev@plt>
mov    -0x40(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    %eax,%edx
call   1060 <mknod@plt>
cmp    $0x0,%rax
je     1228 <create_temp_device_node+0xc8>
jmp    1248 <create_temp_device_node+0xe8>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    127d <create_temp_device_node+0x11d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b4 <create_temp_device_node+0x54>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
lea    0xdb0(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_temp_device_node>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,-0x38(%rbp)
mov    %esi,-0x34(%rbp)
mov    %rdi,-0x40(%rbp)
mov    %rsp,-0x48(%rbp)
movb   $0x0,-0x2c(%rbp)
movl   $0x7665642f,-0x30(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%r12
mov    %r13,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
xor    %r14d,%r14d
lea    0xe53(%rip),%rbx
lea    -0x30(%rbp),%r15
jmp    11ca <create_temp_device_node+0x6a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
cmp    $0x64,%r14d
je     1235 <create_temp_device_node+0xd5>
mov    %r12,%rdi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1040 <snprintf@plt>
mov    %r12,%rdi
call   1080 <util_path_exists@plt>
test   %rax,%rax
jne    11c0 <create_temp_device_node+0x60>
mov    %r13,%rbx
mov    %r15,%r13
mov    0x2de0(%rip),%rax
mov    (%rax),%r15d
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
call   1070 <makedev@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r13,%r15
mov    %rbx,%r13
lea    0xdec(%rip),%rbx
mov    %eax,%edx
call   1060 <mknod@plt>
test   %rax,%rax
jne    11c0 <create_temp_device_node+0x60>
mov    -0x40(%rbp),%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
jmp    1253 <create_temp_device_node+0xf3>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
mov    -0x48(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.create_temp_device_node.path_base = [5 x i8] c"/dev\00"
@PATH_MAX = global i32 0
@.str = [21 x i8] c"%s/zipl-dm-temp-%02d\00"
@S_IFBLK = global i32 0
@stderr = global i32 0
@.str.1 = [55 x i8] c"Error: Could not create temporary device node in '%s'\0A\00"
define i32 @create_temp_device_node(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [5 x i8]
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%13 = bitcast [5 x i8]* %8 to i8*
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %9
%17 = alloca i8, i64 %15
store i64 %15, i64* %10
store i32 0, i32* %11
br label %18
18: ; preds = %40, %3
%19 = load i32, i32* %11
%20 = icmp slt i32 %19, 100
br i1 %20, label %21, label %43
21: ; preds = %18
%22 = trunc i64 %15 to i32
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%24 = load i32, i32* %11
%25 = call i32 @snprintf(i8* %17, i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %23, i32 %24)
%26 = call i64 @util_path_exists(i8* %17)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
br label %40
29: ; preds = %21
%30 = load i32, i32* @S_IFBLK
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = call i32 @makedev(i32 %31, i32 %32)
%34 = call i64 @mknod(i8* %17, i32 %30, i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %29
br label %40
37: ; preds = %29
%38 = load i8*, i8** %5
%39 = call i32 @strcpy(i8* %38, i8* %17)
store i32 0, i32* %4
store i32 1, i32* %12
br label %47
40: ; preds = %36, %28
%41 = load i32, i32* %11
%42 = add nsw i32 %41, 1
store i32 %42, i32* %11
br label %18
43: ; preds = %18
%44 = load i32, i32* @stderr
%45 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %45)
store i32 -1, i32* %4
store i32 1, i32* %12
br label %47
47: ; preds = %43, %37
%48 = load i8*, i8** %9
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@__const.create_temp_device_node.path_base = [5 x i8] c"/dev\00"
@PATH_MAX = global i32 0
@.str = [21 x i8] c"%s/zipl-dm-temp-%02d\00"
@S_IFBLK = global i32 0
@stderr = global i32 0
@.str.1 = [55 x i8] c"Error: Could not create temporary device node in '%s'\0A\00"
define i32 @create_temp_device_node(i8* %0, i32 %1, i32 %2) {
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
br label %10
10: ; preds = %3, %22
%11 = phi i32 [ 0, %3 ], [ %23, %22 ]
%12 = call i32 @snprintf(i8* %9, i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %11)
%13 = call i64 @util_path_exists(i8* %9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* @S_IFBLK
%17 = call i32 @makedev(i32 %1, i32 %2)
%18 = call i64 @mknod(i8* %9, i32 %16, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @strcpy(i8* %0, i8* %9)
br label %28
22: ; preds = %15, %10
%23 = add nuw nsw i32 %11, 1
%24 = icmp eq i32 %23, 100
br i1 %24, label %25, label %10
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %28
28: ; preds = %25, %20
%29 = phi i32 [ 0, %20 ], [ -1, %25 ]
ret i32 %29
}