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

/* Variables and functions */
int /*<<< orphan*/ R_OK;
int __getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ vec_push_back(struct vector *, char *);
int /*<<< orphan*/ *xfopen(char const *, char *);
int file_to_vector(const char *filename, struct vector *v) {
  if (access(filename, R_OK) != 0)
    return 1;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  FILE *fp = xfopen(filename, "r");
  if (fp == NULL)
    return 1;
  while ((read = __getline(&line, &len, fp)) != -1) {
    if (line[read - 1] == '\n')
      line[read - 1] = '\0';
    vec_push_back(v, line);
    line = NULL;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<file_to_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     1188 <file_to_vector+0x38>
movl   $0x1,-0x4(%rbp)
jmp    123a <file_to_vector+0xea>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1030 <xfopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11c3 <file_to_vector+0x73>
movl   $0x1,-0x4(%rbp)
jmp    123a <file_to_vector+0xea>
jmp    11c8 <file_to_vector+0x78>
mov    -0x38(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <__getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     122a <file_to_vector+0xda>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1210 <file_to_vector+0xc0>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <vec_push_back@plt>
movq   $0x0,-0x20(%rbp)
jmp    11c8 <file_to_vector+0x78>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_to_vector>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    121f <file_to_vector+0xcf>
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1030 <xfopen@plt>
test   %rax,%rax
je     121a <file_to_vector+0xca>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1050 <__getline@plt>
cmp    $0xffffffff,%eax
je     120e <file_to_vector+0xbe>
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    11f4 <file_to_vector+0xa4>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1070 <vec_push_back@plt>
movq   $0x0,0x8(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <__getline@plt>
cmp    $0xffffffff,%eax
je     120e <file_to_vector+0xbe>
mov    0x8(%rsp),%rsi
cltq
cmpb   $0xa,-0x1(%rax,%rsi,1)
jne    11d0 <file_to_vector+0x80>
movb   $0x0,-0x1(%rsi,%rax,1)
mov    0x8(%rsp),%rsi
jmp    11d0 <file_to_vector+0x80>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    121f <file_to_vector+0xcf>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.vector = type { i32 }
@R_OK = global i32 0
@.str = [2 x i8] c"r\00"
define i32 @file_to_vector(i8* %0, %struct.vector* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.vector*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %4
store %struct.vector* %1, %struct.vector** %5
%10 = load i8*, i8** %4
%11 = load i32, i32* @R_OK
%12 = call i64 @access(i8* %10, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %48
15: ; preds = %2
store i8* null, i8** %6
store i64 0, i64* %7
%16 = load i8*, i8** %4
%17 = call i32* @xfopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %9
%18 = load i32*, i32** %9
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %3
br label %48
21: ; preds = %15
br label %22
22: ; preds = %41, %21
%23 = load i32*, i32** %9
%24 = call i32 @__getline(i8** %6, i64* %7, i32* %23)
store i32 %24, i32* %8
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %45
26: ; preds = %22
%27 = load i8*, i8** %6
%28 = load i32, i32* %8
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %41
35: ; preds = %26
%36 = load i8*, i8** %6
%37 = load i32, i32* %8
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %35, %26
%42 = load %struct.vector*, %struct.vector** %5
%43 = load i8*, i8** %6
%44 = call i32 @vec_push_back(%struct.vector* %42, i8* %43)
store i8* null, i8** %6
br label %22
45: ; preds = %22
%46 = load i32*, i32** %9
%47 = call i32 @fclose(i32* %46)
store i32 0, i32* %3
br label %48
48: ; preds = %45, %20, %14
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.vector = type { i32 }
@R_OK = global i32 0
@.str = [2 x i8] c"r\00"
define i32 @file_to_vector(i8* %0, %struct.vector* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = load i32, i32* @R_OK
%6 = tail call i64 @access(i8* %0, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %35
8: ; preds = %2
%9 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%10 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%11 = tail call i32* @xfopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %33, label %13
13: ; preds = %8
%14 = call i32 @__getline(i8** %3, i64* %4, i32* %11)
%15 = icmp eq i32 %14, -1
br i1 %15, label %31, label %16
16: ; preds = %13, %26
%17 = phi i32 [ %29, %26 ], [ %14, %13 ]
%18 = load i8*, i8** %3
%19 = add nsw i32 %17, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 10
br i1 %23, label %24, label %26
24: ; preds = %16
store i8 0, i8* %21
%25 = load i8*, i8** %3
br label %26
26: ; preds = %24, %16
%27 = phi i8* [ %25, %24 ], [ %18, %16 ]
%28 = call i32 @vec_push_back(%struct.vector* %1, i8* %27)
store i8* null, i8** %3
%29 = call i32 @__getline(i8** %3, i64* %4, i32* %11)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %16
31: ; preds = %26, %13
%32 = call i32 @fclose(i32* %11)
br label %33
33: ; preds = %8, %31
%34 = phi i32 [ 0, %31 ], [ 1, %8 ]
br label %35
35: ; preds = %2, %33
%36 = phi i32 [ %34, %33 ], [ 1, %2 ]
ret i32 %36
}