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

/* Variables and functions */
int /*<<< orphan*/ assoc_loop(char *, char *, char *, char *, char *, char *);
scalar_t__ check_assoc(char *);
int /*<<< orphan*/ daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int get_failreason();
int getpid();
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ print_log(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  FILE *fp;
  char path[256];
  if (argc == 1) {
    if (check_assoc("apcli0")) {
      printf("ok\n");
    } else {
      printf("no\n");
    }
    return 0;
  }
  if (argc == 2) {
    printf("%x", get_failreason());
    return 0;
  }
  if (argc < 5)
    return -1;
  daemon(0, 0);
  snprintf(path, sizeof(path), "/tmp/apcli-%s.pid", argv[2]);
  fp = fopen(path, "w+");
  if (fp) {
    fprintf(fp, "%d", getpid());
    fclose(fp);
  }
  print_log("main\n");
  setbuf(stdout, NULL);
  openlog("ap_client", 0, 0);
  assoc_loop(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1236 <main+0x66>
lea    0xe06(%rip),%rdi
call   10c0 <check_assoc@plt>
cmp    $0x0,%rax
je     121c <main+0x4c>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    122a <main+0x5a>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    135e <main+0x18e>
cmpl   $0x2,-0x8(%rbp)
jne    1263 <main+0x93>
mov    $0x0,%al
call   1050 <get_failreason@plt>
mov    %eax,%esi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    135e <main+0x18e>
cmpl   $0x5,-0x8(%rbp)
jge    1279 <main+0xa9>
movl   $0xffffffff,-0x4(%rbp)
jmp    135e <main+0x18e>
xor    %esi,%esi
mov    %esi,%edi
call   10d0 <daemon@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x100,%esi
lea    0xd75(%rip),%rdx
call   10a0 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xd74(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12f4 <main+0x124>
mov    -0x18(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x128(%rbp),%rdi
mov    %eax,%edx
lea    0xd41(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fclose@plt>
lea    0xd2f(%rip),%rdi
call   1060 <print_log@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <setbuf@plt>
lea    0xd17(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10f0 <openlog@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%r8
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%r9
call   1030 <assoc_loop@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%edi
je     1217 <main+0x37>
cmp    $0x1,%edi
jne    1236 <main+0x56>
lea    0xe03(%rip),%rdi
call   10d0 <check_assoc@plt>
test   %rax,%rax
je     12f1 <main+0x111>
lea    0xe23(%rip),%rdi
jmp    12f8 <main+0x118>
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <get_failreason@plt>
lea    0xddf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
jmp    1300 <main+0x120>
mov    $0xffffffff,%r14d
cmp    $0x5,%edi
jl     1300 <main+0x120>
mov    %rsi,%rbx
xor    %r14d,%r14d
xor    %edi,%edi
xor    %esi,%esi
call   10e0 <daemon@plt>
mov    0x10(%rbx),%rcx
lea    0xdab(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x100,%esi
call   10b0 <snprintf@plt>
lea    0xda6(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     12a6 <main+0xc6>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd8b(%rip),%rsi
mov    %r15,%rdi
mov    %eax,%edx
call   10c0 <fprintf@plt>
mov    %r15,%rdi
call   1080 <fclose@plt>
lea    0xd75(%rip),%rdi
call   1070 <print_log@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1090 <setbuf@plt>
lea    0xd5f(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <openlog@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    0x18(%rbx),%rdx
mov    0x20(%rbx),%rcx
mov    0x28(%rbx),%r8
mov    0x30(%rbx),%r9
call   1030 <assoc_loop@plt>
jmp    1300 <main+0x120>
lea    0xd3a(%rip),%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"apcli0\00"
@.str.1 = [4 x i8] c"ok\0A\00"
@.str.2 = [4 x i8] c"no\0A\00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [18 x i8] c"/tmp/apcli-%s.pid\00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [6 x i8] c"main\0A\00"
@stdout = global i32 0
@.str.8 = [10 x i8] c"ap_client\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = call i64 @check_assoc(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %17
15: ; preds = %10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
store i32 0, i32* %3
br label %69
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 (...) @get_failreason()
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %22)
store i32 0, i32* %3
br label %69
24: ; preds = %18
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 5
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 -1, i32* %3
br label %69
28: ; preds = %24
%29 = call i32 @daemon(i32 0, i32 0)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @snprintf(i8* %30, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %36, i32** %6
%37 = load i32*, i32** %6
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %45
39: ; preds = %28
%40 = load i32*, i32** %6
%41 = call i32 (...) @getpid()
%42 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %39, %28
%46 = call i32 @print_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%47 = load i32, i32* @stdout
%48 = call i32 @setbuf(i32 %47, i32* null)
%49 = call i32 @openlog(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 0, i32 0)
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 3
%58 = load i8*, i8** %57
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 4
%61 = load i8*, i8** %60
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 5
%64 = load i8*, i8** %63
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 6
%67 = load i8*, i8** %66
%68 = call i32 @assoc_loop(i8* %52, i8* %55, i8* %58, i8* %61, i8* %64, i8* %67)
store i32 0, i32* %3
br label %69
69: ; preds = %45, %27, %21, %17
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [7 x i8] c"apcli0\00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [18 x i8] c"/tmp/apcli-%s.pid\00"
@.str.5 = [3 x i8] c"w+\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [6 x i8] c"main\0A\00"
@stdout = global i32 0
@.str.8 = [10 x i8] c"ap_client\00"
@str = [3 x i8] c"no\00"
@str.9 = [3 x i8] c"ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
switch i32 %0, label %15 [
i32 1, label %5
i32 2, label %12
]
5: ; preds = %2
%6 = tail call i64 @check_assoc(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.9, i64 0, i64 0))
br label %45
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %45
12: ; preds = %2
%13 = tail call i32 (...) @get_failreason()
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %13)
br label %45
15: ; preds = %2
%16 = icmp slt i32 %0, 5
br i1 %16, label %45, label %17
17: ; preds = %15
%18 = tail call i32 @daemon(i32 0, i32 0)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %20)
%22 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = call i32 (...) @getpid()
%26 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = call i32 @fclose(i32* %22)
br label %28
28: ; preds = %24, %17
%29 = call i32 @print_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%30 = load i32, i32* @stdout
%31 = call i32 @setbuf(i32 %30, i32* null)
%32 = call i32 @openlog(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 0, i32 0)
%33 = getelementptr inbounds i8*, i8** %1, i64 1
%34 = load i8*, i8** %33
%35 = load i8*, i8** %19
%36 = getelementptr inbounds i8*, i8** %1, i64 3
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8*, i8** %1, i64 4
%39 = load i8*, i8** %38
%40 = getelementptr inbounds i8*, i8** %1, i64 5
%41 = load i8*, i8** %40
%42 = getelementptr inbounds i8*, i8** %1, i64 6
%43 = load i8*, i8** %42
%44 = call i32 @assoc_loop(i8* %34, i8* %35, i8* %37, i8* %39, i8* %41, i8* %43)
br label %45
45: ; preds = %15, %8, %10, %28, %12
%46 = phi i32 [ 0, %12 ], [ 0, %28 ], [ 0, %10 ], [ 0, %8 ], [ -1, %15 ]
ret i32 %46
}