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

/* Variables and functions */
int /*<<< orphan*/ R_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ add_place_places(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ decode_3986(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
char *strchr(char *, char);
char *strdup(char *);
int strlen(char *);
char *strrchr(char *, char);
int parse_gtk_bookmarks(Display *dpy, const char *fn) {
  char tmp[1024];
  if (access(fn, R_OK)) {
    return -1;
  }
  FILE *bm = fopen(fn, "r");
  if (!bm)
    return -1;
  int found = 0;
  while (fgets(tmp, sizeof(tmp), bm) && strlen(tmp) > 1 &&
         strlen(tmp) < sizeof(tmp)) {
    char *s, *n;
    tmp[strlen(tmp) - 1] = '\0';
    if ((s = strchr(tmp, ' '))) {
      *s = '\0';
      n = strdup(++s);
      decode_3986(tmp);
      if (!add_place_places(dpy, n, tmp)) {
        ++found;
      }
      free(n);
    } else if ((s = strrchr(tmp, '/'))) {
      n = strdup(++s);
      decode_3986(tmp);
      if (!add_place_places(dpy, n, tmp)) {
        ++found;
      }
      free(n);
    }
  }
  fclose(bm);
  return found;
}


x86 assembly (clang, -O0):
<parse_gtk_bookmarks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   10b0 <access@plt>
cmp    $0x0,%rax
je     11eb <parse_gtk_bookmarks+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f7 <parse_gtk_bookmarks+0x247>
mov    -0x18(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    121c <parse_gtk_bookmarks+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f7 <parse_gtk_bookmarks+0x247>
movl   $0x0,-0x42c(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x441(%rbp)
je     128f <parse_gtk_bookmarks+0xdf>
lea    -0x420(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x441(%rbp)
jle    128f <parse_gtk_bookmarks+0xdf>
lea    -0x420(%rbp),%rdi
call   1060 <strlen@plt>
cltq
cmp    $0x400,%rax
setb   %al
mov    %al,-0x441(%rbp)
mov    -0x441(%rbp),%al
test   $0x1,%al
jne    12a2 <parse_gtk_bookmarks+0xf2>
jmp    13e2 <parse_gtk_bookmarks+0x232>
lea    -0x420(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
mov    $0x20,%esi
call   1070 <strchr@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
je     1351 <parse_gtk_bookmarks+0x1a1>
mov    -0x438(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x438(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x438(%rbp)
call   10d0 <strdup@plt>
mov    %rax,-0x440(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <decode_3986@plt>
mov    -0x10(%rbp),%rdi
mov    -0x440(%rbp),%rsi
lea    -0x420(%rbp),%rdx
call   10a0 <add_place_places@plt>
cmp    $0x0,%eax
jne    1340 <parse_gtk_bookmarks+0x190>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
mov    -0x440(%rbp),%rdi
call   1030 <free@plt>
jmp    13dd <parse_gtk_bookmarks+0x22d>
lea    -0x420(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
je     13d8 <parse_gtk_bookmarks+0x228>
mov    -0x438(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x438(%rbp)
call   10d0 <strdup@plt>
mov    %rax,-0x440(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <decode_3986@plt>
mov    -0x10(%rbp),%rdi
mov    -0x440(%rbp),%rsi
lea    -0x420(%rbp),%rdx
call   10a0 <add_place_places@plt>
cmp    $0x0,%eax
jne    13cc <parse_gtk_bookmarks+0x21c>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
mov    -0x440(%rbp),%rdi
call   1030 <free@plt>
jmp    13dd <parse_gtk_bookmarks+0x22d>
jmp    1226 <parse_gtk_bookmarks+0x76>
mov    -0x428(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x42c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_gtk_bookmarks>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <access@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
jne    12d7 <parse_gtk_bookmarks+0x127>
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12d7 <parse_gtk_bookmarks+0x127>
mov    %rax,%r15
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     12cf <parse_gtk_bookmarks+0x11f>
nop
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jl     12cf <parse_gtk_bookmarks+0x11f>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x3ff,%eax
ja     12cf <parse_gtk_bookmarks+0x11f>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    $0x20,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1270 <parse_gtk_bookmarks+0xc0>
movb   $0x0,(%rax)
jmp    1282 <parse_gtk_bookmarks+0xd2>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
je     12b6 <parse_gtk_bookmarks+0x106>
add    $0x1,%rax
mov    %rax,%rdi
call   10d0 <strdup@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <decode_3986@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   10a0 <add_place_places@plt>
cmp    $0x1,%eax
adc    $0x0,%r12d
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
jne    1220 <parse_gtk_bookmarks+0x70>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@R_OK = global i32 0
@.str = [2 x i8] c"r\00"
define i32 @parse_gtk_bookmarks(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %5
%12 = load i32, i32* @R_OK
%13 = call i64 @access(i8* %11, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %93
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp ne i32* %19, null
br i1 %20, label %22, label %21
21: ; preds = %16
store i32 -1, i32* %3
br label %93
22: ; preds = %16
store i32 0, i32* %8
br label %23
23: ; preds = %88, %22
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%25 = load i32*, i32** %7
%26 = call i64 @fgets(i8* %24, i32 1024, i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = icmp sgt i32 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = icmp ult i64 %35, 1024
br label %37
37: ; preds = %32, %28, %23
%38 = phi i1 [ false, %28 ], [ false, %23 ], [ %36, %32 ]
br i1 %38, label %39, label %89
39: ; preds = %37
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %43
store i8 0, i8* %44
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%46 = call i8* @strchr(i8* %45, i8 signext 32)
store i8* %46, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %66
48: ; preds = %39
%49 = load i8*, i8** %9
store i8 0, i8* %49
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %9
%52 = call i8* @strdup(i8* %51)
store i8* %52, i8** %10
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%54 = call i32 @decode_3986(i8* %53)
%55 = load i32*, i32** %4
%56 = load i8*, i8** %10
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%58 = call i32 @add_place_places(i32* %55, i8* %56, i8* %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %63, label %60
60: ; preds = %48
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %63
63: ; preds = %60, %48
%64 = load i8*, i8** %10
%65 = call i32 @free(i8* %64)
br label %88
66: ; preds = %39
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%68 = call i8* @strrchr(i8* %67, i8 signext 47)
store i8* %68, i8** %9
%69 = icmp ne i8* %68, null
br i1 %69, label %70, label %87
70: ; preds = %66
%71 = load i8*, i8** %9
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %9
%73 = call i8* @strdup(i8* %72)
store i8* %73, i8** %10
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%75 = call i32 @decode_3986(i8* %74)
%76 = load i32*, i32** %4
%77 = load i8*, i8** %10
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%79 = call i32 @add_place_places(i32* %76, i8* %77, i8* %78)
%80 = icmp ne i32 %79, 0
br i1 %80, label %84, label %81
81: ; preds = %70
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
br label %84
84: ; preds = %81, %70
%85 = load i8*, i8** %10
%86 = call i32 @free(i8* %85)
br label %87
87: ; preds = %84, %66
br label %88
88: ; preds = %87, %63
br label %23
89: ; preds = %37
%90 = load i32*, i32** %7
%91 = call i32 @fclose(i32* %90)
%92 = load i32, i32* %8
store i32 %92, i32* %3
br label %93
93: ; preds = %89, %21, %15
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@R_OK = global i32 0
@.str = [2 x i8] c"r\00"
define i32 @parse_gtk_bookmarks(i32* %0, i8* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @R_OK
%6 = tail call i64 @access(i8* %1, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %49
8: ; preds = %2
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %49, label %11
11: ; preds = %8
%12 = call i64 @fgets(i8* %4, i32 1024, i32* %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %46, label %14
14: ; preds = %11, %42
%15 = phi i32 [ %43, %42 ], [ 0, %11 ]
%16 = call i32 @strlen(i8* %4)
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %46
18: ; preds = %14
%19 = call i32 @strlen(i8* %4)
%20 = icmp ult i32 %19, 1024
br i1 %20, label %21, label %46
21: ; preds = %18
%22 = call i32 @strlen(i8* %4)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i8* @strchr(i8* %4, i8 signext 32)
%27 = icmp eq i8* %26, null
br i1 %27, label %29, label %28
28: ; preds = %21
store i8 0, i8* %26
br label %32
29: ; preds = %21
%30 = call i8* @strrchr(i8* %4, i8 signext 47)
%31 = icmp eq i8* %30, null
br i1 %31, label %42, label %32
32: ; preds = %29, %28
%33 = phi i8* [ %26, %28 ], [ %30, %29 ]
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = call i8* @strdup(i8* %34)
%36 = call i32 @decode_3986(i8* %4)
%37 = call i32 @add_place_places(i32* %0, i8* %35, i8* %4)
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
%40 = add nsw i32 %15, %39
%41 = call i32 @free(i8* %35)
br label %42
42: ; preds = %32, %29
%43 = phi i32 [ %15, %29 ], [ %40, %32 ]
%44 = call i64 @fgets(i8* %4, i32 1024, i32* %9)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %14
46: ; preds = %18, %14, %42, %11
%47 = phi i32 [ 0, %11 ], [ %43, %42 ], [ %15, %14 ], [ %15, %18 ]
%48 = call i32 @fclose(i32* %9)
br label %49
49: ; preds = %46, %8, %2
%50 = phi i32 [ -1, %2 ], [ %47, %46 ], [ -1, %8 ]
ret i32 %50
}