#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 uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stdout;
int create_and_send_session_key(char *text_key_buffer) {
  FILE *handle = fopen("/dev/urandom", "rb");
  if (handle == NULL) {
    perror("fopen(urandom)");
    return -1;
  }
  uint8_t binary_buffer[(16)];
  size_t got = fread(binary_buffer, 1, (16), handle);
  if (got != (16)) {
    perror("fread(urandom)");
  }
  fclose(handle);
  if (got != (16)) {
    return -1;
  }
  for (int i = 0; i < (16); i++) {
    sprintf(&text_key_buffer[2 * i], "%02X", binary_buffer[i]);
  }
  printf("%s\n", text_key_buffer);
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<create_and_send_session_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b6 <create_and_send_session_key+0x46>
lea    0xe6b(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <create_and_send_session_key+0xff>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1030 <fread@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x10,-0x68(%rbp)
je     11e8 <create_and_send_session_key+0x78>
lea    0xe3c(%rip),%rdi
call   1080 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x10,-0x68(%rbp)
je     1208 <create_and_send_session_key+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <create_and_send_session_key+0xff>
movl   $0x0,-0x6c(%rbp)
cmpl   $0x10,-0x6c(%rbp)
jge    124a <create_and_send_session_key+0xda>
mov    -0x10(%rbp),%rdi
mov    -0x6c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x6c(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
lea    0xdf7(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    120f <create_and_send_session_key+0x9f>
mov    -0x10(%rbp),%rsi
lea    0xdde(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_and_send_session_key>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
lea    0xe7f(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12ec <create_and_send_session_key+0x17c>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x10,%rax
jne    12ff <create_and_send_session_key+0x18f>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%edx
lea    0xe64(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x2(%rbx),%rdi
mov    0x4(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x4(%rbx),%rdi
mov    0x8(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x6(%rbx),%rdi
mov    0xc(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x8(%rbx),%rdi
mov    0x10(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0xa(%rbx),%rdi
mov    0x14(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0xc(%rbx),%rdi
mov    0x18(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0xe(%rbx),%rdi
mov    0x1c(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x10(%rbx),%rdi
mov    0x20(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x12(%rbx),%rdi
mov    0x24(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x14(%rbx),%rdi
mov    0x28(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x16(%rbx),%rdi
mov    0x2c(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x18(%rbx),%rdi
mov    0x30(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x1a(%rbx),%rdi
mov    0x34(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x1c(%rbx),%rdi
mov    0x38(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0x1e(%rbx),%rdi
mov    0x3c(%rsp),%edx
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0xd67(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd1d(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
jmp    12e4 <create_and_send_session_key+0x174>
lea    0xd19(%rip),%rdi
call   1080 <perror@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0xffffffff,%eax
jmp    12e4 <create_and_send_session_key+0x174>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [15 x i8] c"fopen(urandom)\00"
@.str.3 = [15 x i8] c"fread(urandom)\00"
@.str.4 = [5 x i8] c"%02X\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
define i32 @create_and_send_session_key(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [16 x i32]
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %50
13: ; preds = %1
%14 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i64 @fread(i32* %14, i32 1, i32 16, i32* %15)
store i64 %16, i64* %6
%17 = load i64, i64* %6
%18 = icmp ne i64 %17, 16
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = load i64, i64* %6
%25 = icmp ne i64 %24, 16
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -1, i32* %2
br label %50
27: ; preds = %21
store i32 0, i32* %7
br label %28
28: ; preds = %42, %27
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 16
br i1 %30, label %31, label %45
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = load i32, i32* %7
%34 = mul nsw i32 2, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %31
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %28
45: ; preds = %28
%46 = load i8*, i8** %3
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @stdout
%49 = call i32 @fflush(i32 %48)
store i32 0, i32* %2
br label %50
50: ; preds = %45, %26, %11
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [15 x i8] c"fopen(urandom)\00"
@.str.3 = [15 x i8] c"fread(urandom)\00"
@.str.4 = [5 x i8] c"%02X\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
define i32 @create_and_send_session_key(i8* %0) {
%2 = alloca [16 x i32]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %84
7: ; preds = %1
%8 = bitcast [16 x i32]* %2 to i8*
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%10 = call i64 @fread(i32* %9, i32 1, i32 16, i32* %3)
%11 = icmp eq i64 %10, 16
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @fclose(i32* %3)
br label %82
15: ; preds = %7
%16 = tail call i32 @fclose(i32* %3)
%17 = load i32, i32* %9
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds i8, i8* %0, i64 2
%20 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 1
%21 = load i32, i32* %20
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds i8, i8* %0, i64 4
%24 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 2
%25 = load i32, i32* %24
%26 = tail call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds i8, i8* %0, i64 6
%28 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 3
%29 = load i32, i32* %28
%30 = tail call i32 @sprintf(i8* dereferenceable(1) %27, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds i8, i8* %0, i64 8
%32 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 4
%33 = load i32, i32* %32
%34 = tail call i32 @sprintf(i8* dereferenceable(1) %31, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds i8, i8* %0, i64 10
%36 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 5
%37 = load i32, i32* %36
%38 = tail call i32 @sprintf(i8* dereferenceable(1) %35, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds i8, i8* %0, i64 12
%40 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 6
%41 = load i32, i32* %40
%42 = tail call i32 @sprintf(i8* dereferenceable(1) %39, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds i8, i8* %0, i64 14
%44 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 7
%45 = load i32, i32* %44
%46 = tail call i32 @sprintf(i8* dereferenceable(1) %43, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds i8, i8* %0, i64 16
%48 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 8
%49 = load i32, i32* %48
%50 = tail call i32 @sprintf(i8* dereferenceable(1) %47, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds i8, i8* %0, i64 18
%52 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 9
%53 = load i32, i32* %52
%54 = tail call i32 @sprintf(i8* dereferenceable(1) %51, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds i8, i8* %0, i64 20
%56 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 10
%57 = load i32, i32* %56
%58 = tail call i32 @sprintf(i8* dereferenceable(1) %55, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds i8, i8* %0, i64 22
%60 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 11
%61 = load i32, i32* %60
%62 = tail call i32 @sprintf(i8* dereferenceable(1) %59, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds i8, i8* %0, i64 24
%64 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 12
%65 = load i32, i32* %64
%66 = tail call i32 @sprintf(i8* dereferenceable(1) %63, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %65)
%67 = getelementptr inbounds i8, i8* %0, i64 26
%68 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 13
%69 = load i32, i32* %68
%70 = tail call i32 @sprintf(i8* dereferenceable(1) %67, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %69)
%71 = getelementptr inbounds i8, i8* %0, i64 28
%72 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 14
%73 = load i32, i32* %72
%74 = tail call i32 @sprintf(i8* dereferenceable(1) %71, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %73)
%75 = getelementptr inbounds i8, i8* %0, i64 30
%76 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 15
%77 = load i32, i32* %76
%78 = tail call i32 @sprintf(i8* dereferenceable(1) %75, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %77)
%79 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%80 = load i32, i32* @stdout
%81 = tail call i32 @fflush(i32 %80)
br label %82
82: ; preds = %12, %15
%83 = phi i32 [ 0, %15 ], [ -1, %12 ]
br label %84
84: ; preds = %82, %5
%85 = phi i32 [ -1, %5 ], [ %83, %82 ]
ret i32 %85
}