#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 *);
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 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 < 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]);
  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    1222 <main+0x62>
lea    0xe16(%rip),%rdi
call   10b0 <check_assoc@plt>
cmp    $0x0,%rax
je     120a <main+0x4a>
lea    0xe07(%rip),%rdi
call   1080 <printf@plt>
jmp    1216 <main+0x56>
lea    0xdfa(%rip),%rdi
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1315 <main+0x155>
cmpl   $0x5,-0x8(%rbp)
jge    1238 <main+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    1315 <main+0x155>
xor    %esi,%esi
mov    %esi,%edi
call   10c0 <daemon@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x100,%esi
lea    0xdb3(%rip),%rdx
call   1090 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12b3 <main+0xf3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x128(%rbp),%rdi
mov    %eax,%edx
lea    0xd7f(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xd6d(%rip),%rdi
call   1050 <print_log@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <setbuf@plt>
lea    0xd55(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10e0 <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
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    $0x1,%edi
jne    11f2 <main+0x32>
lea    0xe28(%rip),%rdi
call   10b0 <check_assoc@plt>
test   %rax,%rax
je     12a9 <main+0xe9>
lea    0xe45(%rip),%rdi
jmp    12b0 <main+0xf0>
mov    $0xffffffff,%r14d
cmp    $0x5,%edi
jl     12b8 <main+0xf8>
mov    %rsi,%rbx
xor    %r14d,%r14d
xor    %edi,%edi
xor    %esi,%esi
call   10c0 <daemon@plt>
mov    0x10(%rbx),%rcx
lea    0xdec(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x100,%esi
call   1090 <snprintf@plt>
lea    0xde7(%rip),%rsi
mov    %r15,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1262 <main+0xa2>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xdcc(%rip),%rsi
mov    %r15,%rdi
mov    %eax,%edx
call   10a0 <fprintf@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
lea    0xdb6(%rip),%rdi
call   1060 <print_log@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1080 <setbuf@plt>
lea    0xda0(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <openlog@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    0x18(%rbx),%rdx
mov    0x20(%rbx),%rcx
mov    0x28(%rbx),%r8
call   1030 <assoc_loop@plt>
jmp    12b8 <main+0xf8>
lea    0xd7f(%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 = [18 x i8] c"/tmp/apcli-%s.pid\00"
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [6 x i8] c"main\0A\00"
@stdout = global i32 0
@.str.7 = [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 @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 @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 %60
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 5
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 -1, i32* %3
br label %60
22: ; preds = %18
%23 = call i32 @daemon(i32 0, i32 0)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @snprintf(i8* %24, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %30, i32** %6
%31 = load i32*, i32** %6
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %39
33: ; preds = %22
%34 = load i32*, i32** %6
%35 = call i32 (...) @getpid()
%36 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %33, %22
%40 = call i32 @print_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%41 = load i32, i32* @stdout
%42 = call i32 @setbuf(i32 %41, i32* null)
%43 = call i32 @openlog(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 0, i32 0)
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 3
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 4
%55 = load i8*, i8** %54
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 5
%58 = load i8*, i8** %57
%59 = call i32 @assoc_loop(i8* %46, i8* %49, i8* %52, i8* %55, i8* %58)
store i32 0, i32* %3
br label %60
60: ; preds = %39, %21, %17
%61 = load i32, i32* %3
ret i32 %61
}

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