#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 count_lines(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
FILE *openfile_rt(char *filename, int *nl) {
  int nc;
  FILE *stream;
  if ((stream = fopen(filename, "rt")) == NULL) {
    fprintf(stderr, "ERROR (read) : opening file: %s \n", filename);
    exit(1);
  }
  nc = count_lines(stream);
  if (nc < 1) {
    fprintf(stderr, "No sacfiles found in file: %s\n", filename);
    fclose(stream);
    exit(1);
  }
  *nl = nc;
  return stream;
}


x86 assembly (clang, -O0):
<openfile_rt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a1 <openfile_rt+0x51>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe71(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <count_lines@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    11e3 <openfile_rt+0x93>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openfile_rt>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1187 <openfile_rt+0x37>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <count_lines@plt>
test   %eax,%eax
jle    11a9 <openfile_rt+0x59>
mov    %eax,(%r15)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"ERROR (read) : opening file: %s \0A\00"
@.str.2 = [31 x i8] c"No sacfiles found in file: %s\0A\00"
define i32* @openfile_rt(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = call i32 @count_lines(i32* %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %6
%25 = call i32 @fclose(i32* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %15
%28 = load i32, i32* %5
%29 = load i32*, i32** %4
store i32 %28, i32* %29
%30 = load i32*, i32** %6
ret i32* %30
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"ERROR (read) : opening file: %s \0A\00"
@.str.2 = [31 x i8] c"No sacfiles found in file: %s\0A\00"
define i32* @openfile_rt(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i32 @count_lines(i32* %3)
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%15 = tail call i32 @fclose(i32* %3)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
store i32 %10, i32* %1
ret i32* %3
}