#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
char *status_read_file_line(FILE *fp) {
  if (fp == NULL)
    return NULL;
  char *lineptr = NULL;
  size_t len = 256;
  ssize_t read;
  char *retval = NULL;
  char *returnline = NULL;
  lineptr = calloc(1, len * sizeof(char));
  if (lineptr == NULL) {
    fprintf(stderr, "Malloc failed.\n");
    return NULL;
  }
  if ((read = getline(&lineptr, &len, fp)) == -1) {
    free(lineptr);
    return NULL;
  }
  retval = strtok(lineptr, "\n");
  returnline = calloc(1, (strlen(retval) + 1) * sizeof(char));
  strcpy(returnline, retval);
  free(lineptr);
  return returnline;
}


x86 assembly (clang, -O0):
<status_read_file_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <status_read_file_line+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1280 <status_read_file_line+0x110>
movq   $0x0,-0x18(%rbp)
movq   $0x100,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f9 <status_read_file_line+0x89>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1280 <status_read_file_line+0x110>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    122c <status_read_file_line+0xbc>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1280 <status_read_file_line+0x110>
mov    -0x18(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<status_read_file_line>:
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     121b <status_read_file_line+0xab>
mov    %rdi,%rbx
movq   $0x100,0x10(%rsp)
mov    $0x1,%edi
mov    $0x100,%esi
call   1060 <calloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     11ff <status_read_file_line+0x8f>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
mov    0x8(%rsp),%rdi
cmp    $0xffffffff,%eax
je     1216 <status_read_file_line+0xa6>
lea    0xe46(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    121d <status_read_file_line+0xad>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1070 <fprintf@plt>
jmp    121b <status_read_file_line+0xab>
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"Malloc failed.\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @status_read_file_line(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32* %0, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %45
12: ; preds = %1
store i8* null, i8** %4
store i64 256, i64* %5
store i8* null, i8** %7
store i8* null, i8** %8
%13 = load i64, i64* %5
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i8* @calloc(i32 1, i32 %15)
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %45
22: ; preds = %12
%23 = load i32*, i32** %3
%24 = call i32 @getline(i8** %4, i64* %5, i32* %23)
store i32 %24, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
store i8* null, i8** %2
br label %45
29: ; preds = %22
%30 = load i8*, i8** %4
%31 = call i8* @strtok(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = call i32 @strlen(i8* %32)
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 1
%37 = trunc i64 %36 to i32
%38 = call i8* @calloc(i32 1, i32 %37)
store i8* %38, i8** %8
%39 = load i8*, i8** %8
%40 = load i8*, i8** %7
%41 = call i32 @strcpy(i8* %39, i8* %40)
%42 = load i8*, i8** %4
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %8
store i8* %44, i8** %2
br label %45
45: ; preds = %29, %26, %19, %11
%46 = load i8*, i8** %2
ret i8* %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"Malloc failed.\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @status_read_file_line(i32* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = icmp eq i32* %0, null
br i1 %4, label %29, label %5
5: ; preds = %1
%6 = bitcast i8** %2 to i8*
%7 = bitcast i64* %3 to i8*
store i64 256, i64* %3
%8 = tail call dereferenceable_or_null(256) i8* @calloc(i32 1, i32 256)
store i8* %8, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %27
13: ; preds = %5
%14 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%15 = icmp eq i32 %14, -1
%16 = load i8*, i8** %2
br i1 %15, label %17, label %19
17: ; preds = %13
%18 = call i32 @free(i8* %16)
br label %27
19: ; preds = %13
%20 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 1
%23 = call i8* @calloc(i32 1, i32 %22)
%24 = call i32 @strcpy(i8* %23, i8* %20)
%25 = load i8*, i8** %2
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %19, %17, %10
%28 = phi i8* [ null, %10 ], [ null, %17 ], [ %23, %19 ]
br label %29
29: ; preds = %1, %27
%30 = phi i8* [ %28, %27 ], [ null, %1 ]
ret i8* %30
}