#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 process_list {
  int dummy;
};
struct config_file {
  int dummy;
};
struct config {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
struct config *alloc_config();
struct config_file *alloc_config_file();
int /*<<< orphan*/ apply_config(struct config *, struct process_list *);
int /*<<< orphan*/ close_config_file(struct config_file *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct process_list *get_ps();
int open_config_file(struct config_file *, char *);
int /*<<< orphan*/ parse_config(struct config *, struct config_file *);
int /*<<< orphan*/ pdie(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  struct config *config = alloc_config();
  struct config_file *cf = alloc_config_file();
  struct process_list *ps;
  char *filename;
  int err = 0;
  if (argc != 2) {
    usage();
    exit(EXIT_FAILURE);
  }
  filename = argv[1];
  err = open_config_file(cf, filename);
  if (err)
    pdie("Could not open config file");
  parse_config(config, cf);
  ps = get_ps();
  apply_config(config, ps);
  close_config_file(cf);
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <alloc_config@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <alloc_config_file@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f2 <main+0x52>
mov    $0x0,%al
call   10a0 <usage@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <open_config_file@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1224 <main+0x84>
lea    0xde1(%rip),%rdi
call   1070 <pdie@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <parse_config@plt>
mov    $0x0,%al
call   1050 <get_ps@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <apply_config@plt>
mov    -0x20(%rbp),%rdi
call   1030 <close_config_file@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
xor    %eax,%eax
call   1080 <alloc_config@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <alloc_config_file@plt>
cmp    $0x2,%ebp
jne    1215 <main+0x75>
mov    %rax,%rbx
mov    0x8(%r15),%rsi
mov    %rax,%rdi
call   1090 <open_config_file@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11e3 <main+0x43>
lea    0xe22(%rip),%rdi
call   1070 <pdie@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <parse_config@plt>
xor    %eax,%eax
call   1050 <get_ps@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <apply_config@plt>
mov    %rbx,%rdi
call   1030 <close_config_file@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   10a0 <usage@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.config = type { i32 }
%struct.config_file = type { i32 }
%struct.process_list = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [27 x i8] c"Could not open config file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.config*
%7 = alloca %struct.config_file*
%8 = alloca %struct.process_list*
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call %struct.config* (...) @alloc_config()
store %struct.config* %11, %struct.config** %6
%12 = call %struct.config_file* (...) @alloc_config_file()
store %struct.config_file* %12, %struct.config_file** %7
store i32 0, i32* %10
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = call i32 (...) @usage()
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %9
%23 = load %struct.config_file*, %struct.config_file** %7
%24 = load i8*, i8** %9
%25 = call i32 @open_config_file(%struct.config_file* %23, i8* %24)
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = call i32 @pdie(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %19
%31 = load %struct.config*, %struct.config** %6
%32 = load %struct.config_file*, %struct.config_file** %7
%33 = call i32 @parse_config(%struct.config* %31, %struct.config_file* %32)
%34 = call %struct.process_list* (...) @get_ps()
store %struct.process_list* %34, %struct.process_list** %8
%35 = load %struct.config*, %struct.config** %6
%36 = load %struct.process_list*, %struct.process_list** %8
%37 = call i32 @apply_config(%struct.config* %35, %struct.process_list* %36)
%38 = load %struct.config_file*, %struct.config_file** %7
%39 = call i32 @close_config_file(%struct.config_file* %38)
%40 = load i32, i32* %10
ret i32 %40
}

LLVM IR (-O2):
%struct.config = type { i32 }
%struct.config_file = type { i32 }
%struct.process_list = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [27 x i8] c"Could not open config file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call %struct.config* (...) @alloc_config()
%4 = tail call %struct.config_file* (...) @alloc_config_file()
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 (...) @usage()
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @open_config_file(%struct.config_file* %4, i8* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = tail call i32 @pdie(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = tail call i32 @parse_config(%struct.config* %3, %struct.config_file* %4)
%19 = tail call %struct.process_list* (...) @get_ps()
%20 = tail call i32 @apply_config(%struct.config* %3, %struct.process_list* %19)
%21 = tail call i32 @close_config_file(%struct.config_file* %4)
ret i32 %13
}