#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*/ uint32_t;
typedef int /*<<< orphan*/ i;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char *, int);
int open(char *, int /*<<< orphan*/);
int const read(int, char *, int const);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
uint32_t get_random_uuid() {
  const int len = sizeof(uint32_t);
  char data[len];
  int fd, bytes;
  uint32_t i;
  if ((fd = open("/dev/urandom", O_RDONLY)) == -1) {
    fprintf(stderr, "Failed to open /dev/urandom: %s\n", strerror(errno));
    exit(1);
  }
  if (read(fd, data, len) != len) {
    fprintf(stderr, "Error reading /dev/urandom: %s\n", strerror(errno));
    exit(1);
  }
  close(fd);
  memcpy(&i, data, sizeof(i));
  return i;
}


x86 assembly (clang, -O0):
<get_random_uuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x4,-0x4(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11dd <get_random_uuid+0x6d>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe3f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
je     122d <get_random_uuid+0xbd>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe10(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_random_uuid>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11c8 <get_random_uuid+0x58>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    11e8 <get_random_uuid+0x78>
mov    %ebx,%edi
call   1030 <close@plt>
lea    0xc(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e09(%rip),%rax
mov    (%rax),%ebx
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe27(%rip),%rsi
jmp    1206 <get_random_uuid+0x96>
mov    0x2de9(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe28(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"Failed to open /dev/urandom: %s\0A\00"
@errno = global i32 0
@.str.2 = [32 x i8] c"Error reading /dev/urandom: %s\0A\00"
define i32 @get_random_uuid() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 4, i32* %1
%6 = call i8* @llvm.stacksave()
store i8* %6, i8** %2
%7 = alloca i8, i64 4
%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* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* %3
%19 = call i32 @read(i32 %18, i8* %7, i32 4)
%20 = icmp ne i32 %19, 4
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = load i32, i32* %3
%29 = call i32 @close(i32 %28)
%30 = call i32 @memcpy(i32* %5, i8* %7, i32 4)
%31 = load i32, i32* %5
%32 = load i8*, i8** %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"Failed to open /dev/urandom: %s\0A\00"
@errno = global i32 0
@.str.2 = [32 x i8] c"Error reading /dev/urandom: %s\0A\00"
define i32 @get_random_uuid() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = bitcast i32* %1 to i8*
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32 @read(i32 %6, i8* %3, i32 4)
%16 = icmp eq i32 %15, 4
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = tail call i32 @close(i32 %6)
%25 = call i32 @memcpy(i32* %1, i8* %3, i32 4)
%26 = load i32, i32* %1
ret i32 %26
}