#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_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *get_ident_path();
char *malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *read_ident() {
  FILE *f;
  char *p = get_ident_path();
  f = fopen(p, "r");
  free(p);
  char *buf;
  buf = NULL;
  if (f != NULL) {
    fseek(f, 0, SEEK_END);
    long fs = ftell(f);
    fs = ftell(f);
    rewind(f);
    buf = malloc((1 + fs) * (sizeof(char)));
    size_t r = fread(buf, sizeof(char), fs, f);
    fclose(f);
    buf[fs] = '\0';
  }
  return buf;
}


x86 assembly (clang, -O0):
<read_ident>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1070 <get_ident_path@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1250 <read_ident+0xc0>
mov    -0x8(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ident>:
push   %r15
push   %r14
push   %rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <get_ident_path@plt>
mov    %rax,%rbx
lea    0xe57(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     121a <read_ident+0x8a>
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
call   1080 <ftell@plt>
mov    %r15,%rdi
call   1080 <ftell@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1060 <rewind@plt>
lea    0x1(%rbx),%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i8* @read_ident() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = call i8* (...) @get_ident_path()
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %1
%9 = load i8*, i8** %2
%10 = call i32 @free(i8* %9)
store i8* null, i8** %3
%11 = load i32*, i32** %1
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %37
13: ; preds = %0
%14 = load i32*, i32** %1
%15 = load i32, i32* @SEEK_END
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = load i32*, i32** %1
%18 = call i64 @ftell(i32* %17)
store i64 %18, i64* %4
%19 = load i32*, i32** %1
%20 = call i64 @ftell(i32* %19)
store i64 %20, i64* %4
%21 = load i32*, i32** %1
%22 = call i32 @rewind(i32* %21)
%23 = load i64, i64* %4
%24 = add nsw i64 1, %23
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %3
%28 = load i8*, i8** %3
%29 = load i64, i64* %4
%30 = load i32*, i32** %1
%31 = call i64 @fread(i8* %28, i32 1, i64 %29, i32* %30)
store i64 %31, i64* %5
%32 = load i32*, i32** %1
%33 = call i32 @fclose(i32* %32)
%34 = load i8*, i8** %3
%35 = load i64, i64* %4
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 0, i8* %36
br label %37
37: ; preds = %13, %0
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define noalias i8* @read_ident() {
%1 = tail call i8* (...) @get_ident_path()
%2 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @free(i8* %1)
%4 = icmp eq i32* %2, null
br i1 %4, label %17, label %5
5: ; preds = %0
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %2, i32 0, i32 %6)
%8 = tail call i64 @ftell(i32* %2)
%9 = tail call i64 @ftell(i32* %2)
%10 = tail call i32 @rewind(i32* %2)
%11 = trunc i64 %9 to i32
%12 = add i32 %11, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = tail call i64 @fread(i8* %13, i32 1, i64 %9, i32* %2)
%15 = tail call i32 @fclose(i32* %2)
%16 = getelementptr inbounds i8, i8* %13, i64 %9
store i8 0, i8* %16
br label %17
17: ; preds = %5, %0
%18 = phi i8* [ %13, %5 ], [ null, %0 ]
ret i8* %18
}