#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 */
scalar_t__ binfile_syms(int /*<<< orphan*/ *);
char *expand_tilde(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ last_error();
int /*<<< orphan*/ mark_modified(int);
int /*<<< orphan*/ printc_err(char *, char *, int /*<<< orphan*/);
scalar_t__ prompt_abort(int);
int /*<<< orphan*/ stab_clear();
int /*<<< orphan*/ unmark_modified(int);
int cmd_sym_load_add(int clear, char **arg) {
  FILE *in;
  char *path;
  if (clear && prompt_abort(0x01))
    return 0;
  path = expand_tilde(*arg);
  if (!path)
    return -1;
  in = fopen(path, "rb");
  free(path);
  if (!in) {
    printc_err("sym: %s: %s\n", *arg, last_error());
    return -1;
  }
  if (clear) {
    stab_clear();
    unmark_modified(0x01);
  } else {
    mark_modified(0x01);
  }
  if (binfile_syms(in) < 0) {
    fclose(in);
    return -1;
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<cmd_sym_load_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e9 <cmd_sym_load_add+0x39>
mov    $0x1,%edi
call   10a0 <prompt_abort@plt>
cmp    $0x0,%rax
je     11e9 <cmd_sym_load_add+0x39>
movl   $0x0,-0x4(%rbp)
jmp    12ca <cmd_sym_load_add+0x11a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <expand_tilde@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1210 <cmd_sym_load_add+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ca <cmd_sym_load_add+0x11a>
mov    -0x20(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1268 <cmd_sym_load_add+0xb8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1090 <last_error@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xdac(%rip),%rdi
call   1060 <printc_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ca <cmd_sym_load_add+0x11a>
cmpl   $0x0,-0x8(%rbp)
je     1288 <cmd_sym_load_add+0xd8>
mov    $0x0,%al
call   1040 <stab_clear@plt>
mov    $0x1,%edi
call   10d0 <unmark_modified@plt>
jmp    1292 <cmd_sym_load_add+0xe2>
mov    $0x1,%edi
call   10b0 <mark_modified@plt>
mov    -0x18(%rbp),%rdi
call   1070 <binfile_syms@plt>
cmp    $0x0,%rax
jge    12ba <cmd_sym_load_add+0x10a>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ca <cmd_sym_load_add+0x11a>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_sym_load_add>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%r12d
test   %edi,%edi
je     11d7 <cmd_sym_load_add+0x27>
mov    $0x1,%edi
call   10a0 <prompt_abort@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1261 <cmd_sym_load_add+0xb1>
mov    (%r14),%rdi
call   1080 <expand_tilde@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     1261 <cmd_sym_load_add+0xb1>
mov    %rax,%rbp
lea    0xe0d(%rip),%rsi
mov    %rax,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    %rbp,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     1223 <cmd_sym_load_add+0x73>
test   %r12d,%r12d
je     1240 <cmd_sym_load_add+0x90>
xor    %eax,%eax
call   1040 <stab_clear@plt>
mov    $0x1,%edi
call   10d0 <unmark_modified@plt>
jmp    124a <cmd_sym_load_add+0x9a>
mov    (%r14),%rbp
xor    %eax,%eax
call   1090 <last_error@plt>
lea    0xdcf(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <printc_err@plt>
jmp    1261 <cmd_sym_load_add+0xb1>
mov    $0x1,%edi
call   10b0 <mark_modified@plt>
mov    %r15,%rdi
call   1070 <binfile_syms@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <fclose@plt>
sar    $0x3f,%rbx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [13 x i8] c"sym: %s: %s\0A\00"
define i32 @cmd_sym_load_add(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i64 @prompt_abort(i32 1)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 0, i32* %3
br label %51
14: ; preds = %10, %2
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = call i8* @expand_tilde(i8* %16)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %14
store i32 -1, i32* %3
br label %51
21: ; preds = %14
%22 = load i8*, i8** %7
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i8*, i8** %7
%25 = call i32 @free(i8* %24)
%26 = load i32*, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %33, label %28
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = call i32 (...) @last_error()
%32 = call i32 @printc_err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 %31)
store i32 -1, i32* %3
br label %51
33: ; preds = %21
%34 = load i32, i32* %4
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 (...) @stab_clear()
%38 = call i32 @unmark_modified(i32 1)
br label %41
39: ; preds = %33
%40 = call i32 @mark_modified(i32 1)
br label %41
41: ; preds = %39, %36
%42 = load i32*, i32** %6
%43 = call i64 @binfile_syms(i32* %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
store i32 -1, i32* %3
br label %51
48: ; preds = %41
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
store i32 0, i32* %3
br label %51
51: ; preds = %48, %45, %28, %20, %13
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [13 x i8] c"sym: %s: %s\0A\00"
define i32 @cmd_sym_load_add(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i64 @prompt_abort(i32 1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %30
7: ; preds = %4, %2
%8 = load i8*, i8** %1
%9 = tail call i8* @expand_tilde(i8* %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %30, label %11
11: ; preds = %7
%12 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @free(i8* %9)
%14 = icmp eq i32* %12, null
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8*, i8** %1
%17 = tail call i32 (...) @last_error()
%18 = tail call i32 @printc_err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %17)
br label %30
19: ; preds = %11
br i1 %3, label %23, label %20
20: ; preds = %19
%21 = tail call i32 (...) @stab_clear()
%22 = tail call i32 @unmark_modified(i32 1)
br label %25
23: ; preds = %19
%24 = tail call i32 @mark_modified(i32 1)
br label %25
25: ; preds = %23, %20
%26 = tail call i64 @binfile_syms(i32* %12)
%27 = tail call i32 @fclose(i32* %12)
%28 = ashr i64 %26, 63
%29 = trunc i64 %28 to i32
br label %30
30: ; preds = %25, %7, %4, %15
%31 = phi i32 [ -1, %15 ], [ 0, %4 ], [ -1, %7 ], [ %29, %25 ]
ret i32 %31
}