#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 */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int get_next_line(int, char **);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, char *);
int main(void) {
  int i;
  int fd1;
  int tmp;
  char *line;
  int res;
  i = 25;
  line = NULL;
  fd1 = open("test1.txt", O_RDONLY);
  while (i > 0) {
    tmp = fd1;
    res = get_next_line(tmp, &line);
    printf("str is %d = |%s|\n", res, line);
    i--;
  }
  close(fd1);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x19,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11b6 <main+0x76>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1060 <get_next_line@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1176 <main+0x36>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
mov    $0x1a,%ebp
mov    %rsp,%r14
lea    0xe95(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <get_next_line@plt>
mov    (%rsp),%rdx
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1180 <main+0x40>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"test1.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"str is %d = |%s|\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i32 25, i32* %2
store i8* null, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %3
br label %9
9: ; preds = %12, %0
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i32, i32* %3
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = call i32 @get_next_line(i32 %14, i8** %5)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = load i8*, i8** %5
%18 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %17)
%19 = load i32, i32* %2
%20 = add nsw i32 %19, -1
store i32 %20, i32* %2
br label %9
21: ; preds = %9
%22 = load i32, i32* %3
%23 = call i32 @close(i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"test1.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"str is %d = |%s|\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 25, %0 ], [ %10, %5 ]
%7 = call i32 @get_next_line(i32 %4, i8** %1)
%8 = load i8*, i8** %1
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %7, i8* %8)
%10 = add nsw i32 %6, -1
%11 = icmp ugt i32 %6, 1
br i1 %11, label %5, label %12
12: ; preds = %5
%13 = call i32 @close(i32 %4)
ret i32 0
}