#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
char *strchr(char *, char);
__attribute__((__nonnull__)) char *oneline(const char *file) {
  FILE *fp;
  char *ret = (char *)0, *nl;
  size_t len = 0;
  if ((fp = fopen(file, "re")) == (FILE *)0)
    goto err;
  if (getline(&ret, &len, fp) < 0)
    goto out;
  if (len)
    ret[len - 1] = '\0';
  if ((nl = strchr(ret, '\n')))
    *nl = '\0';
out:
  fclose(fp);
err:
  return ret;
}


x86 assembly (clang, -O0):
<oneline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    117f <oneline+0x3f>
jmp    11eb <oneline+0xab>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <getline@plt>
cmp    $0x0,%rax
jge    119f <oneline+0x5f>
jmp    11e2 <oneline+0xa2>
cmpq   $0x0,-0x28(%rbp)
je     11ba <oneline+0x7a>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11dd <oneline+0x9d>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    11e2 <oneline+0xa2>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oneline>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xea3(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b6 <oneline+0x76>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1060 <getline@plt>
test   %rax,%rax
js     11a8 <oneline+0x68>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1192 <oneline+0x52>
mov    (%rsp),%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
mov    (%rsp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a8 <oneline+0x68>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%rax
jmp    11b8 <oneline+0x78>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"re\00"
define i8* @oneline(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %4
store i64 0, i64* %6
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
br label %34
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = call i64 @getline(i8** %4, i64* %6, i32* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %31
16: ; preds = %11
%17 = load i64, i64* %6
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = load i64, i64* %6
%22 = sub i64 %21, 1
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %19, %16
%25 = load i8*, i8** %4
%26 = call i8* @strchr(i8* %25, i8 signext 10)
store i8* %26, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i8*, i8** %5
store i8 0, i8* %29
br label %30
30: ; preds = %28, %24
br label %31
31: ; preds = %30, %15
%32 = load i32*, i32** %3
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %31, %10
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"re\00"
define i8* @oneline(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %26, label %8
8: ; preds = %1
%9 = call i64 @getline(i8** %2, i64* %3, i32* %6)
%10 = icmp slt i64 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %8
%12 = load i64, i64* %3
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = add i64 %12, -1
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %14, %11
%19 = load i8*, i8** %2
%20 = call i8* @strchr(i8* dereferenceable(1) %19, i8 signext 10)
%21 = icmp eq i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %18
store i8 0, i8* %20
br label %23
23: ; preds = %18, %22, %8
%24 = call i32 @fclose(i32* %6)
%25 = load i8*, i8** %2
br label %26
26: ; preds = %1, %23
%27 = phi i8* [ null, %1 ], [ %25, %23 ]
ret i8* %27
}