#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 */
struct csv_row {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct csv_row *csv_parse_str(char *, char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
struct csv_row *csv_read(FILE *fp, char *delim) {
  int str_size = 1024;
  char *str = malloc(sizeof(char) * str_size);
  struct csv_row *row = NULL;
  if (fgets(str, str_size - 1, fp) != 0) {
    row = csv_parse_str(str, delim);
  }
  free(str);
  return row;
}


x86 assembly (clang, -O0):
<csv_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x400,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11a0 <csv_read+0x60>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <csv_parse_str@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csv_read>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3ff,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     117d <csv_read+0x3d>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <csv_parse_str@plt>
mov    %rax,%r14
jmp    1180 <csv_read+0x40>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.csv_row = type { i32 }
define %struct.csv_row* @csv_read(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.csv_row*
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 1024, i32* %5
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = mul i64 1, %9
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %6
store %struct.csv_row* null, %struct.csv_row** %7
%13 = load i8*, i8** %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, 1
%16 = load i32*, i32** %3
%17 = call i64 @fgets(i8* %13, i32 %15, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = load i8*, i8** %4
%22 = call %struct.csv_row* @csv_parse_str(i8* %20, i8* %21)
store %struct.csv_row* %22, %struct.csv_row** %7
br label %23
23: ; preds = %19, %2
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
%26 = load %struct.csv_row*, %struct.csv_row** %7
ret %struct.csv_row* %26
}

LLVM IR (-O2):
%struct.csv_row = type { i32 }
define %struct.csv_row* @csv_read(i32* nocapture %0, i8* %1) {
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = tail call i64 @fgets(i8* %3, i32 1023, i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call %struct.csv_row* @csv_parse_str(i8* %3, i8* %1)
br label %8
8: ; preds = %6, %2
%9 = phi %struct.csv_row* [ %7, %6 ], [ null, %2 ]
%10 = tail call i32 @free(i8* %3)
ret %struct.csv_row* %9
}