#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 cconf {
  int dummy;
};
typedef int /*<<< orphan*/ configfile;

/* Variables and functions */
int /*<<< orphan*/ cconf_free(struct cconf *);
struct cconf *cconf_read(char *);
int /*<<< orphan*/ dlhist_close();
scalar_t__ dlhist_open();
char *env_get_dir();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ proc_cache_close();
scalar_t__ proc_cache_open();
int /*<<< orphan*/ process(struct cconf *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int cmd_run(int argc, char **argv) {
  struct cconf *config;
  char configfile[4096];
  snprintf(configfile, sizeof(configfile), "%s/%s", env_get_dir(), "config");
  config = cconf_read(configfile);
  if (!config) {
    perror(configfile);
    return 1;
  }
  if (proc_cache_open() < 0 || dlhist_open() < 0)
    return 1;
  process(config);
  proc_cache_close();
  dlhist_close();
  cconf_free(config);
  return 0;
}


x86 assembly (clang, -O0):
<cmd_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    $0x0,%al
call   1070 <env_get_dir@plt>
mov    -0x1028(%rbp),%rdi
mov    %rax,%rcx
mov    $0x1000,%esi
lea    0xe23(%rip),%rdx
lea    0xe22(%rip),%r8
call   1030 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
call   1080 <cconf_read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121c <cmd_run+0x7c>
lea    -0x1020(%rbp),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1271 <cmd_run+0xd1>
mov    $0x0,%al
call   10b0 <proc_cache_open@plt>
cmp    $0x0,%rax
jl     123e <cmd_run+0x9e>
mov    $0x0,%al
call   1050 <dlhist_open@plt>
cmp    $0x0,%rax
jge    124a <cmd_run+0xaa>
movl   $0x1,-0x4(%rbp)
jmp    1271 <cmd_run+0xd1>
mov    -0x18(%rbp),%rdi
call   1040 <process@plt>
mov    $0x0,%al
call   10c0 <proc_cache_close@plt>
mov    $0x0,%al
call   1060 <dlhist_close@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <cconf_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_run>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
xor    %eax,%eax
call   1070 <env_get_dir@plt>
lea    0xe49(%rip),%rdx
lea    0xe48(%rip),%r8
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %rax,%rcx
call   1030 <snprintf@plt>
mov    %rbx,%rdi
call   1080 <cconf_read@plt>
test   %rax,%rax
je     122a <cmd_run+0x8a>
mov    %rax,%rbx
xor    %eax,%eax
call   10b0 <proc_cache_open@plt>
mov    $0x1,%ebp
test   %rax,%rax
js     121e <cmd_run+0x7e>
xor    %eax,%eax
call   1050 <dlhist_open@plt>
test   %rax,%rax
js     121e <cmd_run+0x7e>
mov    %rbx,%rdi
call   1040 <process@plt>
xor    %eax,%eax
call   10c0 <proc_cache_close@plt>
xor    %eax,%eax
call   1060 <dlhist_close@plt>
mov    %rbx,%rdi
call   10a0 <cconf_free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rsp,%rdi
call   1090 <perror@plt>
mov    $0x1,%ebp
jmp    121e <cmd_run+0x7e>

LLVM IR (-O0):
%struct.cconf = type { i32 }
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [7 x i8] c"config\00"
define i32 @cmd_run(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.cconf*
%7 = alloca [4096 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%9 = call i8* (...) @env_get_dir()
%10 = call i32 @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%12 = call %struct.cconf* @cconf_read(i8* %11)
store %struct.cconf* %12, %struct.cconf** %6
%13 = load %struct.cconf*, %struct.cconf** %6
%14 = icmp ne %struct.cconf* %13, null
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%17 = call i32 @perror(i8* %16)
store i32 1, i32* %3
br label %32
18: ; preds = %2
%19 = call i64 (...) @proc_cache_open()
%20 = icmp slt i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = call i64 (...) @dlhist_open()
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21, %18
store i32 1, i32* %3
br label %32
25: ; preds = %21
%26 = load %struct.cconf*, %struct.cconf** %6
%27 = call i32 @process(%struct.cconf* %26)
%28 = call i32 (...) @proc_cache_close()
%29 = call i32 (...) @dlhist_close()
%30 = load %struct.cconf*, %struct.cconf** %6
%31 = call i32 @cconf_free(%struct.cconf* %30)
store i32 0, i32* %3
br label %32
32: ; preds = %25, %24, %15
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.cconf = type { i32 }
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [7 x i8] c"config\00"
define i32 @cmd_run(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i8* (...) @env_get_dir()
%6 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = call %struct.cconf* @cconf_read(i8* %4)
%8 = icmp eq %struct.cconf* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @perror(i8* %4)
br label %22
11: ; preds = %2
%12 = call i64 (...) @proc_cache_open()
%13 = icmp slt i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = call i64 (...) @dlhist_open()
%16 = icmp slt i64 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %14
%18 = call i32 @process(%struct.cconf* %7)
%19 = call i32 (...) @proc_cache_close()
%20 = call i32 (...) @dlhist_close()
%21 = call i32 @cconf_free(%struct.cconf* %7)
br label %22
22: ; preds = %11, %14, %17, %9
%23 = phi i32 [ 0, %17 ], [ 1, %9 ], [ 1, %14 ], [ 1, %11 ]
ret i32 %23
}