#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned char *, unsigned char *,
           unsigned char *, unsigned char *, unsigned char *, unsigned char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int read_bootid_node(unsigned char *buf, size_t size) {
  FILE *boot_id;
  if (size != 6)
    return -1;
  boot_id = fopen("/proc/sys/kernel/random/boot_id", "r");
  if (!boot_id)
    return -1;
  if ((fseek(boot_id, 24, SEEK_SET) < 0) ||
      (fscanf(boot_id, "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", &buf[0], &buf[1],
              &buf[2], &buf[3], &buf[4], &buf[5]) != 6)) {
    fclose(boot_id);
    return -1;
  }
  fclose(boot_id);
  return 0;
}


x86 assembly (clang, -O0):
<read_bootid_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x6,-0x18(%rbp)
je     1167 <read_bootid_node+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <read_bootid_node+0xe9>
lea    0xe92(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1195 <read_bootid_node+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <read_bootid_node+0xe9>
mov    -0x20(%rbp),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    $0x18,%esi
call   1050 <fseek@plt>
cmp    $0x0,%rax
jl     1204 <read_bootid_node+0xc4>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%r8
add    $0x2,%r8
mov    -0x10(%rbp),%r9
add    $0x3,%r9
mov    -0x10(%rbp),%r10
add    $0x4,%r10
mov    -0x10(%rbp),%rax
add    $0x5,%rax
lea    0xe35(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <fscanf@plt>
cmp    $0x6,%eax
je     1219 <read_bootid_node+0xd9>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <read_bootid_node+0xe9>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bootid_node>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebp
cmp    $0x6,%rsi
jne    11ce <read_bootid_node+0x8e>
mov    %rdi,%rbx
lea    0xea7(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ce <read_bootid_node+0x8e>
mov    %rax,%r14
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x18,%esi
call   1050 <fseek@plt>
test   %rax,%rax
js     11c1 <read_bootid_node+0x81>
lea    0x1(%rbx),%rcx
lea    0x2(%rbx),%r8
lea    0x3(%rbx),%r9
lea    0x4(%rbx),%rax
lea    0x5(%rbx),%rbp
lea    0xe7f(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
push   %rbp
push   %rax
call   1040 <fscanf@plt>
add    $0x10,%rsp
xor    %ebp,%ebp
cmp    $0x6,%eax
setne  %bpl
neg    %ebp
jmp    11c6 <read_bootid_node+0x86>
mov    $0xffffffff,%ebp
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"/proc/sys/kernel/random/boot_id\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.2 = [37 x i8] c"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx\00"
define i32 @read_bootid_node(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = icmp ne i64 %7, 6
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %42
10: ; preds = %2
%11 = call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %10
store i32 -1, i32* %3
br label %42
15: ; preds = %10
%16 = load i32*, i32** %6
%17 = load i32, i32* @SEEK_SET
%18 = call i64 @fseek(i32* %16, i32 24, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %36, label %20
20: ; preds = %15
%21 = load i32*, i32** %6
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 2
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 3
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 4
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 5
%34 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %25, i8* %27, i8* %29, i8* %31, i8* %33)
%35 = icmp ne i32 %34, 6
br i1 %35, label %36, label %39
36: ; preds = %20, %15
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
store i32 -1, i32* %3
br label %42
39: ; preds = %20
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
store i32 0, i32* %3
br label %42
42: ; preds = %39, %36, %14, %9
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [32 x i8] c"/proc/sys/kernel/random/boot_id\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.2 = [37 x i8] c"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx\00"
define i32 @read_bootid_node(i8* %0, i64 %1) {
%3 = icmp eq i64 %1, 6
br i1 %3, label %4, label %23
4: ; preds = %2
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %23, label %7
7: ; preds = %4
%8 = load i32, i32* @SEEK_SET
%9 = tail call i64 @fseek(i32* %5, i32 24, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = getelementptr inbounds i8, i8* %0, i64 3
%15 = getelementptr inbounds i8, i8* %0, i64 4
%16 = getelementptr inbounds i8, i8* %0, i64 5
%17 = tail call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %12, i8* %13, i8* %14, i8* %15, i8* %16)
%18 = icmp ne i32 %17, 6
%19 = sext i1 %18 to i32
br label %20
20: ; preds = %11, %7
%21 = phi i32 [ -1, %7 ], [ %19, %11 ]
%22 = tail call i32 @fclose(i32* %5)
br label %23
23: ; preds = %20, %4, %2
%24 = phi i32 [ -1, %2 ], [ -1, %4 ], [ %21, %20 ]
ret i32 %24
}