#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_RDWR;
int S_IFBLK;
int S_IRWXU;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *misc_make_path(char *, char *);
int mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int make_temp_devnode(dev_t dev, char **device_node) {
  char *result;
  char *pathname[] = {getenv("TMPDIR"), "/tmp", getenv("HOME"), ".", "/"};
  char filename[] = "zgetdump0000";
  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, "zgetdump%04d", retry);
      result = misc_make_path(pathname[path], filename);
      if (result == NULL)
        return 1;
      rc = mknod(result, mode, dev);
      if (rc == 0) {
        fd = open(result, O_RDWR);
        if (fd != -1) {
          close(fd);
          *device_node = result;
          return 0;
        }
        remove(result);
        retry = 1000;
      } else if (errno != EEXIST)
        retry = 1000;
      free(result);
    }
  }
  fprintf(stderr, "Unable to create temporary device node: %s",
          strerror(errno));
  return 1;
}


x86 assembly (clang, -O0):
<make_temp_devnode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe4a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x40(%rbp)
lea    0xe41(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe3b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe27(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe1e(%rip),%rax
mov    %rax,-0x4d(%rbp)
mov    0xe1c(%rip),%eax
mov    %eax,-0x45(%rbp)
mov    0xe17(%rip),%al
mov    %al,-0x41(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    0x2dcb(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    $0x5,%rax
jae    135c <make_temp_devnode+0x1bc>
mov    -0x58(%rbp),%eax
cmpq   $0x0,-0x40(%rbp,%rax,8)
jne    124a <make_temp_devnode+0xaa>
jmp    134e <make_temp_devnode+0x1ae>
movl   $0x0,-0x5c(%rbp)
cmpl   $0x3e8,-0x5c(%rbp)
jge    1349 <make_temp_devnode+0x1a9>
lea    -0x4d(%rbp),%rdi
mov    -0x5c(%rbp),%edx
lea    0xdb6(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x58(%rbp),%eax
mov    -0x40(%rbp,%rax,8),%rdi
lea    -0x4d(%rbp),%rsi
call   10a0 <misc_make_path@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    129d <make_temp_devnode+0xfd>
movl   $0x1,-0x4(%rbp)
jmp    1390 <make_temp_devnode+0x1f0>
mov    -0x18(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1080 <mknod@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
jne    130c <make_temp_devnode+0x16c>
mov    -0x18(%rbp),%rdi
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
je     12f7 <make_temp_devnode+0x157>
mov    -0x64(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1390 <make_temp_devnode+0x1f0>
mov    -0x18(%rbp),%rdi
call   1050 <remove@plt>
movl   $0x3e8,-0x5c(%rbp)
jmp    1332 <make_temp_devnode+0x192>
mov    0x2ca5(%rip),%rax
mov    (%rax),%rax
mov    0x2cab(%rip),%rcx
cmp    (%rcx),%rax
je     132d <make_temp_devnode+0x18d>
movl   $0x3e8,-0x5c(%rbp)
jmp    1332 <make_temp_devnode+0x192>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1251 <make_temp_devnode+0xb1>
jmp    134e <make_temp_devnode+0x1ae>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1229 <make_temp_devnode+0x89>
mov    0x2c5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2c49(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xcab(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_temp_devnode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,0x4(%rsp)
lea    0xe42(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbp
mov    %rax,0x20(%rsp)
lea    0xe35(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe2e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x30(%rsp)
lea    0xe22(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xe18(%rip),%rax
mov    %rax,0x40(%rsp)
movabs $0x30303030706d75,%rax
mov    %rax,0x15(%rsp)
movabs $0x706d75647465677a,%rax
75 6d 70
mov    %rax,0x10(%rsp)
mov    0x2dab(%rip),%rax
mov    0x2dbc(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
xor    %r12d,%r12d
lea    0x10(%rsp),%r13
test   %rbp,%rbp
je     12f6 <make_temp_devnode+0x156>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xffffffff,%r15d
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15d
mov    %r13,%rdi
lea    0xdb4(%rip),%rsi
mov    %r15d,%edx
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   10a0 <misc_make_path@plt>
test   %rax,%rax
je     1339 <make_temp_devnode+0x199>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
mov    0x4(%rsp),%edx
call   1080 <mknod@plt>
test   %eax,%eax
je     12d0 <make_temp_devnode+0x130>
mov    0x2d12(%rip),%rax
mov    (%rax),%rax
mov    0x2d18(%rip),%rcx
cmp    (%rcx),%rax
jne    12ee <make_temp_devnode+0x14e>
mov    %r14,%rdi
call   1040 <free@plt>
cmp    $0x3e7,%r15d
jb     1260 <make_temp_devnode+0xc0>
jmp    12f6 <make_temp_devnode+0x156>
nopl   0x0(%rax,%rax,1)
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    134d <make_temp_devnode+0x1ad>
mov    %r14,%rdi
call   1050 <remove@plt>
mov    %r14,%rdi
call   1040 <free@plt>
add    $0x1,%r12
cmp    $0x5,%r12
je     1310 <make_temp_devnode+0x170>
mov    0x20(%rsp,%r12,8),%rbp
test   %rbp,%rbp
jne    1250 <make_temp_devnode+0xb0>
jmp    12f6 <make_temp_devnode+0x156>
mov    0x2ca9(%rip),%rax
mov    (%rax),%ebx
mov    0x2c98(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xd00(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
call   1060 <close@plt>
mov    0x8(%rsp),%rax
mov    %r14,(%rax)
xor    %eax,%eax
jmp    133e <make_temp_devnode+0x19e>

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

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