#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 */

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ closelog();
int create_pidfile(char const *);
scalar_t__ parse_args(int, char **);
int /*<<< orphan*/ remove_pidfile(char const *, int);
scalar_t__ signal_config();
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int usbwall_run();
int main(int argc, char *argv[]) {
  if (parse_args(argc, argv))
    return 0;
  if (signal_config()) {
    syslog(LOG_ERR, "Signal handling init failed.");
    return 1;
  }
  const char *pidfile = "/var/run/usbwall.pid";
  int pidfile_fd = -1;
  if ((pidfile_fd = create_pidfile(pidfile)) == -1)
    return 1;
  syslog(LOG_INFO, "Usbwall started");
  int rcode = usbwall_run();
  syslog(LOG_INFO, "Usbwall terminated");
  remove_pidfile(pidfile, pidfile_fd);
  closelog();
  return !!rcode;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <parse_args@plt>
cmp    $0x0,%rax
je     11a8 <main+0x38>
movl   $0x0,-0x4(%rbp)
jmp    1267 <main+0xf7>
mov    $0x0,%al
call   1090 <signal_config@plt>
cmp    $0x0,%rax
je     11da <main+0x6a>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1070 <syslog@plt>
movl   $0x1,-0x4(%rbp)
jmp    1267 <main+0xf7>
lea    0xe3c(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <create_pidfile@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    120d <main+0x9d>
movl   $0x1,-0x4(%rbp)
jmp    1267 <main+0xf7>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1070 <syslog@plt>
mov    $0x0,%al
call   1080 <usbwall_run@plt>
mov    %eax,-0x20(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1070 <syslog@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <remove_pidfile@plt>
mov    $0x0,%al
call   1040 <closelog@plt>
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
call   1050 <parse_args@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    120c <main+0x9c>
xor    %eax,%eax
call   1090 <signal_config@plt>
test   %rax,%rax
je     11af <main+0x3f>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1070 <syslog@plt>
mov    $0x1,%eax
jmp    120c <main+0x9c>
lea    0xe67(%rip),%rdi
call   1030 <create_pidfile@plt>
cmp    $0xffffffff,%eax
je     11a8 <main+0x38>
mov    %eax,%ebx
mov    0x2e17(%rip),%r14
mov    (%r14),%edi
lea    0xe5f(%rip),%rsi
call   1070 <syslog@plt>
xor    %eax,%eax
call   1080 <usbwall_run@plt>
mov    %eax,%ebp
mov    (%r14),%edi
lea    0xe57(%rip),%rsi
call   1070 <syslog@plt>
lea    0xe26(%rip),%rdi
mov    %ebx,%esi
call   1060 <remove_pidfile@plt>
xor    %eax,%eax
call   1040 <closelog@plt>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [29 x i8] c"Signal handling init failed.\00"
@.str.1 = [21 x i8] c"/var/run/usbwall.pid\00"
@LOG_INFO = global i32 0
@.str.2 = [16 x i8] c"Usbwall started\00"
@.str.3 = [19 x i8] c"Usbwall terminated\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i64 @parse_args(i32 %9, i8** %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %40
14: ; preds = %2
%15 = call i64 (...) @signal_config()
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @LOG_ERR
%19 = call i32 @syslog(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %40
20: ; preds = %14
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8** %6
store i32 -1, i32* %7
%21 = load i8*, i8** %6
%22 = call i32 @create_pidfile(i8* %21)
store i32 %22, i32* %7
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 1, i32* %3
br label %40
25: ; preds = %20
%26 = load i32, i32* @LOG_INFO
%27 = call i32 @syslog(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 (...) @usbwall_run()
store i32 %28, i32* %8
%29 = load i32, i32* @LOG_INFO
%30 = call i32 @syslog(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = call i32 @remove_pidfile(i8* %31, i32 %32)
%34 = call i32 (...) @closelog()
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
%38 = xor i1 %37, true
%39 = zext i1 %38 to i32
store i32 %39, i32* %3
br label %40
40: ; preds = %25, %24, %17, %13
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [29 x i8] c"Signal handling init failed.\00"
@.str.1 = [21 x i8] c"/var/run/usbwall.pid\00"
@LOG_INFO = global i32 0
@.str.2 = [16 x i8] c"Usbwall started\00"
@.str.3 = [19 x i8] c"Usbwall terminated\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @parse_args(i32 %0, i8** %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %24
5: ; preds = %2
%6 = tail call i64 (...) @signal_config()
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = load i32, i32* @LOG_ERR
%10 = tail call i32 @syslog(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %24
11: ; preds = %5
%12 = tail call i32 @create_pidfile(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32 %12, -1
br i1 %13, label %24, label %14
14: ; preds = %11
%15 = load i32, i32* @LOG_INFO
%16 = tail call i32 @syslog(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 (...) @usbwall_run()
%18 = load i32, i32* @LOG_INFO
%19 = tail call i32 @syslog(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i32 @remove_pidfile(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%21 = tail call i32 (...) @closelog()
%22 = icmp ne i32 %17, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %14, %11, %2, %8
%25 = phi i32 [ 1, %8 ], [ 0, %2 ], [ %23, %14 ], [ 1, %11 ]
ret i32 %25
}