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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ initializeString(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char);
int /*<<< orphan*/ strncat(char *, char *, int);
void generateUUID(char *uuid) {
  char data[16];
  initializeString(data, 16);
  FILE *fp;
  fp = fopen("/dev/urandom", "r");
  if (fread(&data, 1, 16, fp) != 16) {
  }
  fclose(fp);
  char buffer[3];
  initializeString(uuid, 33);
  initializeString(buffer, 3);
  int i = 0;
  for (i = 0; i < 16; i++) {
    snprintf(buffer, 3, "%02X", data[i]);
    strncat(uuid, buffer, 2);
  }
}


x86 assembly (clang, -O0):
<generateUUID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
call   1030 <initializeString@plt>
lea    0xe7f(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1040 <fread@plt>
cmp    $0x10,%eax
je     11b6 <generateUUID+0x56>
jmp    11b6 <generateUUID+0x56>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8(%rbp),%rdi
mov    $0x21,%esi
call   1030 <initializeString@plt>
lea    -0x2b(%rbp),%rdi
mov    $0x3,%esi
call   1030 <initializeString@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x10,-0x30(%rbp)
jge    1231 <generateUUID+0xd1>
lea    -0x2b(%rbp),%rdi
movslq -0x30(%rbp),%rax
mov    $0x3,%esi
lea    0xe08(%rip),%rdx
movsbl -0x20(%rbp,%rax,1),%ecx
call   1060 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2b(%rbp),%rsi
mov    $0x2,%edx
call   1070 <strncat@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11e9 <generateUUID+0x89>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateUUID>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x10,%esi
call   1030 <initializeString@plt>
lea    0xe79(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
mov    $0x21,%esi
call   1030 <initializeString@plt>
lea    0xd(%rsp),%r12
mov    %r12,%rdi
mov    $0x3,%esi
call   1030 <initializeString@plt>
xor    %ebx,%ebx
lea    0xe34(%rip),%r15
nopl   0x0(%rax,%rax,1)
movsbl 0x10(%rsp,%rbx,1),%ecx
mov    %r12,%rdi
mov    $0x3,%esi
mov    %r15,%rdx
call   1060 <snprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1070 <strncat@plt>
add    $0x1,%rbx
cmp    $0x10,%rbx
jne    11e0 <generateUUID+0x80>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%02X\00"
define void @generateUUID(i8* %0) {
%2 = alloca i8*
%3 = alloca [16 x i8]
%4 = alloca i32*
%5 = alloca [3 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%8 = call i32 @initializeString(i8* %7, i32 16)
%9 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = bitcast [16 x i8]* %3 to i8**
%11 = load i32*, i32** %4
%12 = call i32 @fread(i8** %10, i32 1, i32 16, i32* %11)
%13 = icmp ne i32 %12, 16
br i1 %13, label %14, label %15
14: ; preds = %1
br label %15
15: ; preds = %14, %1
%16 = load i32*, i32** %4
%17 = call i32 @fclose(i32* %16)
%18 = load i8*, i8** %2
%19 = call i32 @initializeString(i8* %18, i32 33)
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%21 = call i32 @initializeString(i8* %20, i32 3)
store i32 0, i32* %6
store i32 0, i32* %6
br label %22
22: ; preds = %35, %15
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 16
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @snprintf(i8* %26, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 signext %30)
%32 = load i8*, i8** %2
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%34 = call i32 @strncat(i8* %32, i8* %33, i32 2)
br label %35
35: ; preds = %25
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %22
38: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%02X\00"
define void @generateUUID(i8* %0) {
%2 = alloca [16 x i8]
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%5 = call i32 @initializeString(i8* %4, i32 16)
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast [16 x i8]* %2 to i8**
%8 = call i32 @fread(i8** %7, i32 1, i32 16, i32* %6)
%9 = call i32 @fclose(i32* %6)
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%11 = call i32 @initializeString(i8* %0, i32 33)
%12 = call i32 @initializeString(i8* %10, i32 3)
br label %13
13: ; preds = %1, %13
%14 = phi i64 [ 0, %1 ], [ %19, %13 ]
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @snprintf(i8* %10, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 signext %16)
%18 = call i32 @strncat(i8* %0, i8* %10, i32 2)
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, 16
br i1 %20, label %21, label %13
21: ; preds = %13
ret void
}