#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*/ buffer;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_file(char const *, char *);
int BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, char);
int read_text_file(const char *file_path) {
  char buffer[1024];
  int buffer_length = sizeof(buffer);
  int i, result = -1;
  if (file_path != NULL) {
    BIO *file_io = BIO_new_file(file_path, "r");
    if (file_io != NULL) {
      result = BIO_read(file_io, buffer, buffer_length);
      for (i = 0; i < result; i++) {
        printf("%c", buffer[i]);
      }
      BIO_free(file_io);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<read_text_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x400,-0x414(%rbp)
movl   $0xffffffff,-0x41c(%rbp)
ff ff ff
cmpq   $0x0,-0x8(%rbp)
je     120e <read_text_file+0xce>
mov    -0x8(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1060 <BIO_new_file@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     1209 <read_text_file+0xc9>
mov    -0x428(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1030 <BIO_read@plt>
mov    %eax,-0x41c(%rbp)
movl   $0x0,-0x418(%rbp)
mov    -0x418(%rbp),%eax
cmp    -0x41c(%rbp),%eax
jge    11fd <read_text_file+0xbd>
movslq -0x418(%rbp),%rax
lea    0xe26(%rip),%rdi
movsbl -0x410(%rbp,%rax,1),%esi
ff
call   1040 <printf@plt>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    11bc <read_text_file+0x7c>
mov    -0x428(%rbp),%rdi
call   1050 <BIO_free@plt>
jmp    120e <read_text_file+0xce>
mov    -0x41c(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_text_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     11bd <read_text_file+0x7d>
lea    0xe9f(%rip),%rsi
call   1060 <BIO_new_file@plt>
test   %rax,%rax
je     11bd <read_text_file+0x7d>
mov    %rax,%r14
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0x400,%edx
call   1030 <BIO_read@plt>
mov    %eax,%r15d
test   %eax,%eax
jle    11b5 <read_text_file+0x75>
mov    %r15d,%ebp
xor    %ebx,%ebx
lea    0xe71(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%rsp,%rbx,1),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <read_text_file+0x60>
mov    %r14,%rdi
call   1050 <BIO_free@plt>
mov    %r15d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @read_text_file(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %2
store i32 1024, i32* %4
store i32 -1, i32* %6
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %37
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32* @BIO_new_file(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %36
15: ; preds = %10
%16 = load i32*, i32** %7
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @BIO_read(i32* %16, i8* %17, i32 %18)
store i32 %19, i32* %6
store i32 0, i32* %5
br label %20
20: ; preds = %30, %15
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %28)
br label %30
30: ; preds = %24
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %20
33: ; preds = %20
%34 = load i32*, i32** %7
%35 = call i32 @BIO_free(i32* %34)
br label %36
36: ; preds = %33, %10
br label %37
37: ; preds = %36, %1
%38 = load i32, i32* %6
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @read_text_file(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = tail call i32* @BIO_new_file(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %22, label %8
8: ; preds = %5
%9 = call i32 @BIO_read(i32* %6, i8* %3, i32 1024)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %18, %13 ]
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %16)
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, %12
br i1 %19, label %20, label %13
20: ; preds = %13, %8
%21 = call i32 @BIO_free(i32* %6)
br label %22
22: ; preds = %5, %20, %1
%23 = phi i32 [ -1, %1 ], [ %9, %20 ], [ -1, %5 ]
ret i32 %23
}