#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ stderr;
char *generate_container_id() {
  FILE *uuid_source = fopen("/proc/sys/kernel/random/uuid", "r");
  if (uuid_source == NULL) {
    fprintf(stderr,
            "Cannot fopen /proc/sys/kernel/random/uuid (error code %d)\n",
            errno);
    return (char *)-1;
  }
  char *container_id = malloc(37 + 1);
  fgets(container_id, 37, uuid_source);
  if (errno != 0) {
    fprintf(
        stderr,
        "Cannot get content of /proc/sys/kernel/random/uuid (error code %d)\n",
        errno);
    free(container_id);
    fclose(uuid_source);
    return (char *)-1;
  }
  fclose(uuid_source);
  return container_id;
}


x86 assembly (clang, -O0):
<generate_container_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b8 <generate_container_id+0x58>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
lea    0xe7c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1239 <generate_container_id+0xd9>
mov    $0x26,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x25,%esi
call   1050 <fgets@plt>
mov    0x2df9(%rip),%rax
cmpl   $0x0,(%rax)
je     1228 <generate_container_id+0xc8>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
lea    0xe59(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1239 <generate_container_id+0xd9>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_container_id>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d7 <generate_container_id+0x77>
mov    %rax,%r14
mov    $0x26,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x25,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
test   %edx,%edx
je     11fe <generate_container_id+0x9e>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0xffffffffffffffff,%rbx
jmp    1206 <generate_container_id+0xa6>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
lea    0xe2f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffffffffffff,%rbx
jmp    1206 <generate_container_id+0xa6>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/proc/sys/kernel/random/uuid\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [59 x i8] c"Cannot fopen /proc/sys/kernel/random/uuid (error code %d)\0A\00"
@errno = global i32 0
@.str.3 = [68 x i8] c"Cannot get content of /proc/sys/kernel/random/uuid (error code %d)\0A\00"
define i8* @generate_container_id() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca i8*
%4 = call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %9)
store i8* inttoptr (i64 -1 to i8*), i8** %1
br label %30
11: ; preds = %0
%12 = call i8* @malloc(i32 38)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = load i32*, i32** %2
%15 = call i32 @fgets(i8* %13, i32 37, i32* %14)
%16 = load i32, i32* @errno
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
%24 = load i32*, i32** %2
%25 = call i32 @fclose(i32* %24)
store i8* inttoptr (i64 -1 to i8*), i8** %1
br label %30
26: ; preds = %11
%27 = load i32*, i32** %2
%28 = call i32 @fclose(i32* %27)
%29 = load i8*, i8** %3
store i8* %29, i8** %1
br label %30
30: ; preds = %26, %18, %7
%31 = load i8*, i8** %1
ret i8* %31
}

LLVM IR (-O2):
@.str = [29 x i8] c"/proc/sys/kernel/random/uuid\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [59 x i8] c"Cannot fopen /proc/sys/kernel/random/uuid (error code %d)\0A\00"
@errno = global i32 0
@.str.3 = [68 x i8] c"Cannot get content of /proc/sys/kernel/random/uuid (error code %d)\0A\00"
define i8* @generate_container_id() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = load i32, i32* @errno
%6 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %19
7: ; preds = %0
%8 = tail call dereferenceable_or_null(38) i8* @malloc(i32 38)
%9 = tail call i32 @fgets(i8* %8, i32 37, i32* %1)
%10 = load i32, i32* @errno
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%15 = tail call i32 @free(i8* %8)
%16 = tail call i32 @fclose(i32* %1)
br label %19
17: ; preds = %7
%18 = tail call i32 @fclose(i32* %1)
br label %19
19: ; preds = %12, %17, %3
%20 = phi i8* [ inttoptr (i64 -1 to i8*), %3 ], [ inttoptr (i64 -1 to i8*), %12 ], [ %8, %17 ]
ret i8* %20
}