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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
scalar_t__ snprintf(char *, int, char *, int);
int /*<<< orphan*/ unused(char *, ...);
int guid_init(char guid[(16 * 2 + 1)]) {
  int rc = -1;
  int fd = open("/dev/urandom", O_RDONLY);
  if (fd == -1) {
    do {
      unused("open(/dev/urandom) failed");
    } while (0);
    goto _out;
  }
  char bytes[16];
  if (read(fd, bytes, 16) == -1) {
    do {
      unused("read() failed");
    } while (0);
    goto _out_close;
  }
  for (int i = 0, j = 0; i < 16; ++i)
    j += snprintf(guid + j, (16 * 2 + 1) - j, "%.02x", (int)bytes[i] & 0xff);
  do {
    unused("guid=%s", &guid[0]);
  } while (0);
  rc = 0;
_out_close:
  if (close(fd) == -1)
    do {
      unused("close(%i) failed");
    } while (0);
_out:
  return rc;
}


x86 assembly (clang, -O0):
<guid_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    119d <guid_init+0x4d>
jmp    118a <guid_init+0x3a>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1060 <unused@plt>
jmp    127c <guid_init+0x12c>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
jne    11cf <guid_init+0x7f>
jmp    11bc <guid_init+0x6c>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1060 <unused@plt>
jmp    124e <guid_init+0xfe>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    1230 <guid_init+0xe0>
mov    -0x8(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    $0x21,%esi
sub    -0x28(%rbp),%esi
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%ecx
and    $0xff,%ecx
lea    0xe25(%rip),%rdx
call   1030 <snprintf@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11dd <guid_init+0x8d>
jmp    1235 <guid_init+0xe5>
mov    -0x8(%rbp),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1060 <unused@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1277 <guid_init+0x127>
jmp    1264 <guid_init+0x114>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1060 <unused@plt>
jmp    1277 <guid_init+0x127>
jmp    127c <guid_init+0x12c>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guid_init>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r12
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11dc <guid_init+0x8c>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11eb <guid_init+0x9b>
xor    %ebp,%ebp
lea    0xe9c(%rip),%r14
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movslq %eax,%rbx
lea    (%r12,%rbx,1),%rdi
mov    $0x21,%esi
sub    %ebx,%esi
movzbl (%rsp,%rbp,1),%ecx
mov    %r14,%rdx
call   1030 <snprintf@plt>
add    %ebx,%eax
add    $0x1,%rbp
cmp    $0x10,%rbp
jne    11a0 <guid_init+0x50>
lea    0xe6e(%rip),%rdi
xor    %r14d,%r14d
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <unused@plt>
jmp    11ff <guid_init+0xaf>
mov    $0xffffffff,%r14d
lea    0xe24(%rip),%rdi
jmp    1213 <guid_init+0xc3>
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1060 <unused@plt>
mov    $0xffffffff,%r14d
mov    %r15d,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    121a <guid_init+0xca>
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1060 <unused@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"open(/dev/urandom) failed\00"
@.str.2 = [14 x i8] c"read() failed\00"
@.str.3 = [6 x i8] c"%.02x\00"
@.str.4 = [8 x i8] c"guid=%s\00"
@.str.5 = [17 x i8] c"close(%i) failed\00"
define i32 @guid_init(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %1
br label %13
13: ; preds = %12
%14 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13
br label %65
16: ; preds = %1
%17 = load i32, i32* %4
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 16)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %16
br label %22
22: ; preds = %21
%23 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22
br label %56
25: ; preds = %16
store i32 0, i32* %6
store i32 0, i32* %7
br label %26
26: ; preds = %47, %25
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 16
br i1 %28, label %29, label %50
29: ; preds = %26
%30 = load i8*, i8** %2
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i32, i32* %7
%35 = sub nsw i32 33, %34
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = and i32 %40, 255
%42 = call i64 @snprintf(i8* %33, i32 %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %7
br label %47
47: ; preds = %29
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %26
50: ; preds = %26
br label %51
51: ; preds = %50
%52 = load i8*, i8** %2
%53 = getelementptr inbounds i8, i8* %52, i64 0
%54 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %51
store i32 0, i32* %3
br label %56
56: ; preds = %55, %24
%57 = load i32, i32* %4
%58 = call i32 @close(i32 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %56
br label %61
61: ; preds = %60
%62 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %63
63: ; preds = %61
br label %64
64: ; preds = %63, %56
br label %65
65: ; preds = %64, %15
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"open(/dev/urandom) failed\00"
@.str.2 = [14 x i8] c"read() failed\00"
@.str.3 = [6 x i8] c"%.02x\00"
@.str.4 = [8 x i8] c"guid=%s\00"
@.str.5 = [17 x i8] c"close(%i) failed\00"
define i32 @guid_init(i8* %0) {
%2 = alloca [16 x i8]
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %32, label %6
6: ; preds = %1
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%8 = call i32 @read(i32 %4, i8* %7, i32 16)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = tail call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %28
12: ; preds = %14
%13 = tail call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %28
14: ; preds = %6, %14
%15 = phi i64 [ %26, %14 ], [ 0, %6 ]
%16 = phi i32 [ %25, %14 ], [ 0, %6 ]
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = sub nsw i32 33, %16
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %15
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = tail call i64 @snprintf(i8* %18, i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = trunc i64 %23 to i32
%25 = add i32 %16, %24
%26 = add nuw nsw i64 %15, 1
%27 = icmp eq i64 %26, 16
br i1 %27, label %12, label %14
28: ; preds = %12, %10
%29 = phi i32 [ -1, %10 ], [ 0, %12 ]
%30 = tail call i32 @close(i32 %4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %28, %1
%33 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %28 ]
%34 = phi i32 [ -1, %1 ], [ %29, %28 ]
%35 = tail call i32 (i8*, ...) @unused(i8* %33)
br label %36
36: ; preds = %32, %28
%37 = phi i32 [ %29, %28 ], [ %34, %32 ]
ret i32 %37
}