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

/* Variables and functions */
scalar_t__ EEXIST;
int /*<<< orphan*/ O_RDONLY;
int S_IFBLK;
int S_IRWXU;
int /*<<< orphan*/ close(int);
char *dinfo_make_path(char *, char *);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ warnx(char *);
int dinfo_create_devnode(dev_t dev, char **devno) {
  char *result;
  char *pathname[] = {"/dev", getenv("TMPDIR"), "/tmp", getenv("HOME"), ".",
                      "/"};
  char filename[] = "dasdinfo0000";
  mode_t mode;
  unsigned int path;
  int retry;
  int rc;
  int fd;
  mode = S_IFBLK | S_IRWXU;
  for (path = 0; path < (sizeof(pathname) / sizeof((pathname)[0])); path++) {
    if (pathname[path] == NULL)
      continue;
    for (retry = 0; retry < 1000; retry++) {
      sprintf(filename, "dasdinfo%04d", retry);
      result = dinfo_make_path(pathname[path], filename);
      if (result == NULL)
        return -1;
      rc = mknod(result, mode, dev);
      if (rc == 0) {
        fd = open(result, O_RDONLY);
        if (fd != -1) {
          close(fd);
          *devno = result;
          return 0;
        }
        remove(result);
        retry = 1000;
      } else if (errno != EEXIST) {
        retry = 1000;
      }
      free(result);
    }
  }
  warnx("Error: Unable to create temporary device node");
  return -1;
}


x86 assembly (clang, -O0):
<dinfo_create_devnode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe57(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe51(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x48(%rbp)
lea    0xe48(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe42(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
lea    0xe37(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe2e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe25(%rip),%rax
mov    %rax,-0x5d(%rbp)
mov    0xe23(%rip),%eax
mov    %eax,-0x55(%rbp)
mov    0xe1e(%rip),%al
mov    %al,-0x51(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    0x2dcd(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    $0x6,%rax
jae    135a <dinfo_create_devnode+0x1ca>
mov    -0x68(%rbp),%eax
cmpq   $0x0,-0x50(%rbp,%rax,8)
jne    1248 <dinfo_create_devnode+0xb8>
jmp    134c <dinfo_create_devnode+0x1bc>
movl   $0x0,-0x6c(%rbp)
cmpl   $0x3e8,-0x6c(%rbp)
jge    1347 <dinfo_create_devnode+0x1b7>
lea    -0x5d(%rbp),%rdi
mov    -0x6c(%rbp),%edx
lea    0xdbd(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x68(%rbp),%eax
mov    -0x50(%rbp,%rax,8),%rdi
lea    -0x5d(%rbp),%rsi
call   1090 <dinfo_make_path@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    129b <dinfo_create_devnode+0x10b>
movl   $0xffffffff,-0x4(%rbp)
jmp    136d <dinfo_create_devnode+0x1dd>
mov    -0x18(%rbp),%rdi
mov    -0x64(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1080 <mknod@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0x0,-0x70(%rbp)
jne    130a <dinfo_create_devnode+0x17a>
mov    -0x18(%rbp),%rdi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
je     12f5 <dinfo_create_devnode+0x165>
mov    -0x74(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    136d <dinfo_create_devnode+0x1dd>
mov    -0x18(%rbp),%rdi
call   1050 <remove@plt>
movl   $0x3e8,-0x6c(%rbp)
jmp    1330 <dinfo_create_devnode+0x1a0>
mov    0x2caf(%rip),%rax
mov    (%rax),%rax
mov    0x2cad(%rip),%rcx
cmp    (%rcx),%rax
je     132b <dinfo_create_devnode+0x19b>
movl   $0x3e8,-0x6c(%rbp)
jmp    1330 <dinfo_create_devnode+0x1a0>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    124f <dinfo_create_devnode+0xbf>
jmp    134c <dinfo_create_devnode+0x1bc>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1227 <dinfo_create_devnode+0x97>
lea    0xcd3(%rip),%rdi
call   1060 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dinfo_create_devnode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,0x4(%rsp)
lea    0xe52(%rip),%rbp
mov    %rbp,0x20(%rsp)
lea    0xe4b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x28(%rsp)
lea    0xe41(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe3a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x38(%rsp)
lea    0xe2e(%rip),%rax
mov    %rax,0x40(%rsp)
lea    0xe24(%rip),%rax
mov    %rax,0x48(%rsp)
movabs $0x303030306f666e,%rax
mov    %rax,0x15(%rsp)
movabs $0x6f666e6964736164,%rax
6e 66 6f
mov    %rax,0x10(%rsp)
mov    0x2db2(%rip),%rax
mov    0x2dc3(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
xor    %r15d,%r15d
lea    0x10(%rsp),%r13
test   %rbp,%rbp
je     12e6 <dinfo_create_devnode+0x156>
nopw   0x0(%rax,%rax,1)
mov    $0xffffffff,%r12d
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12d
mov    %r13,%rdi
lea    0xdc9(%rip),%rsi
mov    %r12d,%edx
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1090 <dinfo_make_path@plt>
test   %rax,%rax
je     130c <dinfo_create_devnode+0x17c>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
mov    0x4(%rsp),%edx
call   1080 <mknod@plt>
test   %eax,%eax
je     12c0 <dinfo_create_devnode+0x130>
mov    0x2d2a(%rip),%rax
mov    (%rax),%rax
mov    0x2d28(%rip),%rcx
cmp    (%rcx),%rax
jne    12de <dinfo_create_devnode+0x14e>
mov    %r14,%rdi
call   1040 <free@plt>
cmp    $0x3e7,%r12d
jb     1250 <dinfo_create_devnode+0xc0>
jmp    12e6 <dinfo_create_devnode+0x156>
nopl   0x0(%rax,%rax,1)
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
jne    1320 <dinfo_create_devnode+0x190>
mov    %r14,%rdi
call   1050 <remove@plt>
mov    %r14,%rdi
call   1040 <free@plt>
add    $0x1,%r15
cmp    $0x6,%r15
je     1300 <dinfo_create_devnode+0x170>
mov    0x20(%rsp,%r15,8),%rbp
test   %rbp,%rbp
jne    1240 <dinfo_create_devnode+0xb0>
jmp    12e6 <dinfo_create_devnode+0x156>
lea    0xd2d(%rip),%rdi
call   1060 <warnx@plt>
mov    $0xffffffff,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
call   1070 <close@plt>
mov    0x8(%rsp),%rax
mov    %r14,(%rax)
xor    %eax,%eax
jmp    1311 <dinfo_create_devnode+0x181>

LLVM IR (-O0):
@.str = [5 x i8] c"/dev\00"
@.str.1 = [7 x i8] c"TMPDIR\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [2 x i8] c"/\00"
@__const.dinfo_create_devnode.filename = [13 x i8] c"dasdinfo0000\00"
@S_IFBLK = global i32 0
@S_IRWXU = global i32 0
@.str.6 = [13 x i8] c"dasdinfo%04d\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.7 = [46 x i8] c"Error: Unable to create temporary device node\00"
define i32 @dinfo_create_devnode(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [6 x i8*]
%8 = alloca [13 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %15
%17 = getelementptr inbounds i8*, i8** %15, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %18
%20 = getelementptr inbounds i8*, i8** %18, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds i8*, i8** %20, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8** %21
%22 = bitcast [13 x i8]* %8 to i8*
%23 = load i32, i32* @S_IFBLK
%24 = load i32, i32* @S_IRWXU
%25 = or i32 %23, %24
store i32 %25, i32* %9
store i32 0, i32* %10
br label %26
26: ; preds = %88, %2
%27 = load i32, i32* %10
%28 = zext i32 %27 to i64
%29 = icmp ult i64 %28, 6
br i1 %29, label %30, label %91
30: ; preds = %26
%31 = load i32, i32* %10
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %30
br label %88
37: ; preds = %30
store i32 0, i32* %11
br label %38
38: ; preds = %84, %37
%39 = load i32, i32* %11
%40 = icmp slt i32 %39, 1000
br i1 %40, label %41, label %87
41: ; preds = %38
%42 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%43 = load i32, i32* %11
%44 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %10
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%50 = call i8* @dinfo_make_path(i8* %48, i8* %49)
store i8* %50, i8** %6
%51 = load i8*, i8** %6
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %54
53: ; preds = %41
store i32 -1, i32* %3
br label %93
54: ; preds = %41
%55 = load i8*, i8** %6
%56 = load i32, i32* %9
%57 = load i32, i32* %4
%58 = call i32 @mknod(i8* %55, i32 %56, i32 %57)
store i32 %58, i32* %12
%59 = load i32, i32* %12
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %75
61: ; preds = %54
%62 = load i8*, i8** %6
%63 = load i32, i32* @O_RDONLY
%64 = call i32 @open(i8* %62, i32 %63)
store i32 %64, i32* %13
%65 = load i32, i32* %13
%66 = icmp ne i32 %65, -1
br i1 %66, label %67, label %72
67: ; preds = %61
%68 = load i32, i32* %13
%69 = call i32 @close(i32 %68)
%70 = load i8*, i8** %6
%71 = load i8**, i8*** %5
store i8* %70, i8** %71
store i32 0, i32* %3
br label %93
72: ; preds = %61
%73 = load i8*, i8** %6
%74 = call i32 @remove(i8* %73)
store i32 1000, i32* %11
br label %81
75: ; preds = %54
%76 = load i64, i64* @errno
%77 = load i64, i64* @EEXIST
%78 = icmp ne i64 %76, %77
br i1 %78, label %79, label %80
79: ; preds = %75
store i32 1000, i32* %11
br label %80
80: ; preds = %79, %75
br label %81
81: ; preds = %80, %72
%82 = load i8*, i8** %6
%83 = call i32 @free(i8* %82)
br label %84
84: ; preds = %81
%85 = load i32, i32* %11
%86 = add nsw i32 %85, 1
store i32 %86, i32* %11
br label %38
87: ; preds = %38
br label %88
88: ; preds = %87, %36
%89 = load i32, i32* %10
%90 = add i32 %89, 1
store i32 %90, i32* %10
br label %26
91: ; preds = %26
%92 = call i32 @warnx(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %3
br label %93
93: ; preds = %91, %67, %53
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str = [5 x i8] c"/dev\00"
@.str.1 = [7 x i8] c"TMPDIR\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [2 x i8] c"/\00"
@__const.dinfo_create_devnode.filename = [13 x i8] c"dasdinfo0000\00"
@S_IFBLK = global i32 0
@S_IRWXU = global i32 0
@.str.6 = [13 x i8] c"dasdinfo%04d\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.7 = [46 x i8] c"Error: Unable to create temporary device node\00"
define i32 @dinfo_create_devnode(i32 %0, i8** nocapture writeonly %1) {
%3 = alloca [6 x i8*]
%4 = alloca [13 x i8]
%5 = bitcast [6 x i8*]* %3 to i8*
%6 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 1
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %8, i8** %7
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 3
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %11, i8** %10
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%15 = load i32, i32* @S_IFBLK
%16 = load i32, i32* @S_IRWXU
%17 = or i32 %16, %15
br label %18
18: ; preds = %51, %2
%19 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ], [ %53, %51 ]
%20 = phi i64 [ 0, %2 ], [ %49, %51 ]
%21 = icmp eq i8* %19, null
br i1 %21, label %48, label %22
22: ; preds = %18, %44
%23 = phi i32 [ %46, %44 ], [ 0, %18 ]
%24 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%25 = call i8* @dinfo_make_path(i8* %19, i8* %14)
%26 = icmp eq i8* %25, null
br i1 %26, label %56, label %27
27: ; preds = %22
%28 = call i32 @mknod(i8* %25, i32 %17, i32 %0)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* %25, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i32 @close(i32 %32)
store i8* %25, i8** %1
br label %56
36: ; preds = %30
%37 = call i32 @remove(i8* %25)
br label %42
38: ; preds = %27
%39 = load i64, i64* @errno
%40 = load i64, i64* @EEXIST
%41 = icmp eq i64 %39, %40
br i1 %41, label %44, label %42
42: ; preds = %38, %36
%43 = call i32 @free(i8* %25)
br label %48
44: ; preds = %38
%45 = call i32 @free(i8* %25)
%46 = add nuw nsw i32 %23, 1
%47 = icmp ult i32 %23, 999
br i1 %47, label %22, label %48
48: ; preds = %44, %42, %18
%49 = add nuw nsw i64 %20, 1
%50 = icmp eq i64 %49, 6
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 %49
%53 = load i8*, i8** %52
br label %18
54: ; preds = %48
%55 = call i32 @warnx(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0))
br label %56
56: ; preds = %22, %54, %34
%57 = phi i32 [ 0, %34 ], [ -1, %54 ], [ -1, %22 ]
ret i32 %57
}