#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strtok(char *, char *);
char *omb_utils_read(const char *key) {
  char tmp[255];
  sprintf(tmp, "%s/%s/.%s", "/omb", "open-multiboot", key);
  FILE *fd = fopen(tmp, "r");
  if (fd) {
    char line[1024];
    if (fgets(line, 1024, fd)) {
      strtok(line, "\n");
      char *ret = malloc(strlen(line) + 1);
      strcpy(ret, line);
      fclose(fd);
      return ret;
    }
    fclose(fd);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<omb_utils_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%r8
lea    0xe5f(%rip),%rsi
lea    0xe62(%rip),%rdx
lea    0xe60(%rip),%rcx
call   10a0 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     126b <omb_utils_read+0xeb>
lea    -0x520(%rbp),%rdi
mov    -0x118(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     125f <omb_utils_read+0xdf>
lea    -0x520(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1090 <strtok@plt>
lea    -0x520(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x528(%rbp)
mov    -0x528(%rbp),%rdi
lea    -0x520(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x118(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x528(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1273 <omb_utils_read+0xf3>
mov    -0x118(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x530,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<omb_utils_read>:
push   %r15
push   %r14
push   %rbx
sub    $0x500,%rsp
mov    %rdi,%r8
lea    0xe6a(%rip),%rsi
lea    0xe6d(%rip),%rdx
lea    0xe6b(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1228 <omb_utils_read+0xa8>
mov    %rax,%r14
lea    0x100(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1220 <omb_utils_read+0xa0>
lea    0xe39(%rip),%rsi
lea    0x100(%rsp),%r15
mov    %r15,%rdi
call   1090 <strtok@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    122a <omb_utils_read+0xaa>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x500,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%s/%s/.%s\00"
@.str.1 = [5 x i8] c"/omb\00"
@.str.2 = [15 x i8] c"open-multiboot\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"\0A\00"
define i8* @omb_utils_read(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [255 x i8]
%5 = alloca i32*
%6 = alloca [1024 x i8]
%7 = alloca i8*
store i8* %0, i8** %3
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %36
15: ; preds = %1
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = load i32*, i32** %5
%18 = call i64 @fgets(i8* %16, i32 1024, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = call i32 @strtok(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %24, 1
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i32*, i32** %5
%31 = call i32 @fclose(i32* %30)
%32 = load i8*, i8** %7
store i8* %32, i8** %2
br label %37
33: ; preds = %15
%34 = load i32*, i32** %5
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %33, %1
store i8* null, i8** %2
br label %37
37: ; preds = %36, %20
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s/%s/.%s\00"
@.str.1 = [5 x i8] c"/omb\00"
@.str.2 = [15 x i8] c"open-multiboot\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"\0A\00"
define i8* @omb_utils_read(i8* %0) {
%2 = alloca [255 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %21, label %8
8: ; preds = %1
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i64 @fgets(i8* %9, i32 1024, i32* %6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @fclose(i32* %6)
br label %21
14: ; preds = %8
%15 = call i32 @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%16 = call i64 @strlen(i8* %9)
%17 = add nsw i64 %16, 1
%18 = call i8* @malloc(i64 %17)
%19 = call i32 @strcpy(i8* %18, i8* %9)
%20 = call i32 @fclose(i32* %6)
br label %21
21: ; preds = %1, %12, %14
%22 = phi i8* [ %18, %14 ], [ null, %12 ], [ null, %1 ]
ret i8* %22
}