#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 */

/* Variables and functions */
char *get_next_line(int);
int my_strlen(char *);
int open_tmp_file();
int /*<<< orphan*/ write(int, char *, int);
int read_file(int fd_file) {
  char *str;
  int fd_output;
  fd_output = open_tmp_file();
  while ((str = get_next_line(fd_file)) != NULL) {
    if (str == NULL)
      return (-1);
    write(fd_output, str, my_strlen(str));
    write(fd_output, "\n", 1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <open_tmp_file@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <get_next_line@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11c0 <read_file+0x80>
cmpq   $0x0,-0x10(%rbp)
jne    1182 <read_file+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <read_file+0x87>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
lea    0xe4f(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
jmp    1155 <read_file+0x15>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %eax,%eax
call   1050 <open_tmp_file@plt>
mov    %eax,%ebp
mov    %r15d,%edi
call   1060 <get_next_line@plt>
test   %rax,%rax
je     11a3 <read_file+0x63>
mov    %rax,%rbx
lea    0xe96(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <my_strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r15d,%edi
call   1060 <get_next_line@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1170 <read_file+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @read_file(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32 (...) @open_tmp_file()
store i32 %6, i32* %5
br label %7
7: ; preds = %15, %1
%8 = load i32, i32* %3
%9 = call i8* @get_next_line(i32 %8)
store i8* %9, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 -1, i32* %2
br label %24
15: ; preds = %11
%16 = load i32, i32* %5
%17 = load i8*, i8** %4
%18 = load i8*, i8** %4
%19 = call i32 @my_strlen(i8* %18)
%20 = call i32 @write(i32 %16, i8* %17, i32 %19)
%21 = load i32, i32* %5
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %7
23: ; preds = %7
store i32 0, i32* %2
br label %24
24: ; preds = %23, %14
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @read_file(i32 %0) {
%2 = tail call i32 (...) @open_tmp_file()
%3 = tail call i8* @get_next_line(i32 %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %12, label %5
5: ; preds = %1, %5
%6 = phi i8* [ %10, %5 ], [ %3, %1 ]
%7 = tail call i32 @my_strlen(i8* %6)
%8 = tail call i32 @write(i32 %2, i8* %6, i32 %7)
%9 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = tail call i8* @get_next_line(i32 %0)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %5
12: ; preds = %5, %1
ret i32 0
}