#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getenv(char *);
void *malloc(int);
char *mfm_append_paths(int /*<<< orphan*/, char *);
int /*<<< orphan*/ mfm_cut_1310(char *);
char **realloc(char **, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char **mfm_read_bookmarks() {
  char *fname = mfm_append_paths(getenv("HOME"), ".local/etc/mfm/bookmarks");
  FILE *f = fopen(fname, "r");
  free(fname);
  if (!f) {
    return NULL;
  }
  int cur = 0, tsz = 10;
  char **res = malloc(sizeof(char *) * tsz);
  char buf[256];
  while (!feof(f)) {
    if (!fgets(buf, 256, f)) {
      continue;
    }
    mfm_cut_1310(buf);
    int l = strlen(buf);
    if (!l) {
      continue;
    }
    res[cur] = malloc(l + 1);
    strcpy(res[cur], buf);
    cur++;
    if (cur == tsz) {
      tsz += 10;
      res = realloc(res, sizeof(char *) * tsz);
    }
  }
  res = realloc(res, sizeof(char *) * (cur + 1));
  res[cur] = NULL;
  return res;
}


x86 assembly (clang, -O0):
<mfm_read_bookmarks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
lea    0xe3e(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xe35(%rip),%rsi
call   10a0 <mfm_append_paths@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
cmpq   $0x0,-0x18(%rbp)
jne    120e <mfm_read_bookmarks+0x5e>
movq   $0x0,-0x8(%rbp)
jmp    1342 <mfm_read_bookmarks+0x192>
movl   $0x0,-0x1c(%rbp)
movl   $0xa,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    124d <mfm_read_bookmarks+0x9d>
jmp    130f <mfm_read_bookmarks+0x15f>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1080 <fgets@plt>
cmp    $0x0,%eax
jne    1270 <mfm_read_bookmarks+0xc0>
jmp    122f <mfm_read_bookmarks+0x7f>
lea    -0x130(%rbp),%rdi
call   1070 <mfm_cut_1310@plt>
lea    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jne    12a0 <mfm_read_bookmarks+0xf0>
jmp    122f <mfm_read_bookmarks+0x7f>
mov    -0x134(%rbp),%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x130(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    130a <mfm_read_bookmarks+0x15a>
mov    -0x20(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   10c0 <realloc@plt>
mov    %rax,-0x28(%rbp)
jmp    122f <mfm_read_bookmarks+0x7f>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   10c0 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfm_read_bookmarks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe38(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe31(%rip),%rsi
mov    %eax,%edi
call   10a0 <mfm_append_paths@plt>
mov    %rax,%r14
lea    0xe39(%rip),%rsi
mov    %rax,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <free@plt>
xor    %r14d,%r14d
test   %rbx,%rbx
je     12b6 <mfm_read_bookmarks+0x106>
mov    $0x50,%edi
call   10b0 <malloc@plt>
mov    %rax,%r15
mov    $0xa,%r13d
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1298 <mfm_read_bookmarks+0xe8>
mov    %r12,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %eax,%eax
je     1220 <mfm_read_bookmarks+0x70>
mov    %r12,%rdi
call   1070 <mfm_cut_1310@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
je     1220 <mfm_read_bookmarks+0x70>
add    $0x1,%eax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %r14d,%ecx
mov    %rax,(%r15,%rcx,8)
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <strcpy@plt>
add    $0x1,%r14d
cmp    %r13d,%r14d
jne    1220 <mfm_read_bookmarks+0x70>
lea    0xa(%r13),%ebp
lea    0x50(,%r13,8),%esi
mov    %r15,%rdi
call   10c0 <realloc@plt>
mov    %rax,%r15
mov    %r13d,%r14d
mov    %ebp,%r13d
jmp    1220 <mfm_read_bookmarks+0x70>
lea    0x8(,%r14,8),%esi
mov    %r15,%rdi
call   10c0 <realloc@plt>
mov    %r14d,%ecx
movq   $0x0,(%rax,%rcx,8)
mov    %rax,%r14
mov    %r14,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [25 x i8] c".local/etc/mfm/bookmarks\00"
@.str.2 = [2 x i8] c"r\00"
define i8** @mfm_read_bookmarks() {
%1 = alloca i8**
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i8* @mfm_append_paths(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %3
%13 = load i8*, i8** %2
%14 = call i32 @free(i8* %13)
%15 = load i32*, i32** %3
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %0
store i8** null, i8*** %1
br label %87
18: ; preds = %0
store i32 0, i32* %4
store i32 10, i32* %5
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = mul i64 8, %20
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
%24 = bitcast i8* %23 to i8**
store i8** %24, i8*** %6
br label %25
25: ; preds = %73, %43, %35, %18
%26 = load i32*, i32** %3
%27 = call i32 @feof(i32* %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %30, label %74
30: ; preds = %25
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = load i32*, i32** %3
%33 = call i32 @fgets(i8* %31, i32 256, i32* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %30
br label %25
36: ; preds = %30
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%38 = call i32 @mfm_cut_1310(i8* %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %36
br label %25
44: ; preds = %36
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
%47 = call i8* @malloc(i32 %46)
%48 = load i8**, i8*** %6
%49 = load i32, i32* %4
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
store i8* %47, i8** %51
%52 = load i8**, i8*** %6
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%58 = call i32 @strcpy(i8* %56, i8* %57)
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
%61 = load i32, i32* %4
%62 = load i32, i32* %5
%63 = icmp eq i32 %61, %62
br i1 %63, label %64, label %73
64: ; preds = %44
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 10
store i32 %66, i32* %5
%67 = load i8**, i8*** %6
%68 = load i32, i32* %5
%69 = sext i32 %68 to i64
%70 = mul i64 8, %69
%71 = trunc i64 %70 to i32
%72 = call i8** @realloc(i8** %67, i32 %71)
store i8** %72, i8*** %6
br label %73
73: ; preds = %64, %44
br label %25
74: ; preds = %25
%75 = load i8**, i8*** %6
%76 = load i32, i32* %4
%77 = add nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = mul i64 8, %78
%80 = trunc i64 %79 to i32
%81 = call i8** @realloc(i8** %75, i32 %80)
store i8** %81, i8*** %6
%82 = load i8**, i8*** %6
%83 = load i32, i32* %4
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
store i8* null, i8** %85
%86 = load i8**, i8*** %6
store i8** %86, i8*** %1
br label %87
87: ; preds = %74, %17
%88 = load i8**, i8*** %1
ret i8** %88
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [25 x i8] c".local/etc/mfm/bookmarks\00"
@.str.2 = [2 x i8] c"r\00"
define i8** @mfm_read_bookmarks() {
%1 = alloca [256 x i8]
%2 = tail call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = tail call i8* @mfm_append_paths(i32 %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @free(i8* %3)
%6 = icmp eq i32* %4, null
br i1 %6, label %46, label %7
7: ; preds = %0
%8 = tail call dereferenceable_or_null(80) i8* @malloc(i32 80)
%9 = bitcast i8* %8 to i8**
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
br label %11
11: ; preds = %7, %36
%12 = phi i32 [ 0, %7 ], [ %13, %36 ]
%13 = phi i32 [ 10, %7 ], [ %37, %36 ]
%14 = phi i8** [ %9, %7 ], [ %39, %36 ]
br label %15
15: ; preds = %11, %28
%16 = phi i32 [ %34, %28 ], [ %12, %11 ]
br label %17
17: ; preds = %15, %24
br label %18
18: ; preds = %17, %21
%19 = call i32 @feof(i32* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %40
21: ; preds = %18
%22 = call i32 @fgets(i8* %10, i32 256, i32* %4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %18, label %24
24: ; preds = %21
%25 = call i32 @mfm_cut_1310(i8* %10)
%26 = call i32 @strlen(i8* %10)
%27 = icmp eq i32 %26, 0
br i1 %27, label %17, label %28
28: ; preds = %24
%29 = add nsw i32 %26, 1
%30 = call i8* @malloc(i32 %29)
%31 = zext i32 %16 to i64
%32 = getelementptr inbounds i8*, i8** %14, i64 %31
store i8* %30, i8** %32
%33 = call i32 @strcpy(i8* %30, i8* %10)
%34 = add nuw nsw i32 %16, 1
%35 = icmp eq i32 %34, %13
br i1 %35, label %36, label %15
36: ; preds = %28
%37 = add nuw nsw i32 %13, 10
%38 = shl i32 %37, 3
%39 = call i8** @realloc(i8** %14, i32 %38)
br label %11
40: ; preds = %18
%41 = shl i32 %16, 3
%42 = add i32 %41, 8
%43 = call i8** @realloc(i8** %14, i32 %42)
%44 = zext i32 %16 to i64
%45 = getelementptr inbounds i8*, i8** %43, i64 %44
store i8* null, i8** %45
br label %46
46: ; preds = %0, %40
%47 = phi i8** [ %43, %40 ], [ null, %0 ]
ret i8** %47
}