#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 sockaddr_ll {
  int dummy;
};
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ SIGKILL;
scalar_t__ chdir(char *);
scalar_t__ eap_keep_alive(int, struct sockaddr_ll const *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *format_time();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
scalar_t__ getpid();
int /*<<< orphan*/ kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int eap_daemon(int skfd, struct sockaddr_ll const *skaddr) {
  FILE *kpalvfd = fopen("/tmp/cwnu-drcom-eap.pid", "r+");
  if (NULL == kpalvfd) {
    fprintf(stderr, "[EAP:KPALV] No process pidfile. %s: %s\n",
            "/tmp/cwnu-drcom-eap.pid", strerror(errno));
    ;
    kpalvfd = fopen("/tmp/cwnu-drcom-eap.pid", "w+");
    if (NULL == kpalvfd) {
      fprintf(stderr, "[EAP:KPALV] Detect pid file eror(%s)! quit!\n",
              strerror(errno));
      ;
      return -1;
    }
  }
  pid_t oldpid;
  fseek(kpalvfd, 0L, SEEK_SET);
  if ((1 == fscanf(kpalvfd, "%d", (int *)&oldpid)) && (oldpid != (pid_t)-1)) {
    ((void)0);
    kill(oldpid, SIGKILL);
  }
  setsid();
  if (0 != chdir("/"))
    fprintf(stderr, "[EAP:KPALV:WARN] %s\n", strerror(errno));
  ;
  umask(0);
  pid_t curpid = getpid();
  ((void)0);
  if (NULL == (kpalvfd = freopen("/tmp/cwnu-drcom-eap.pid", "w+", kpalvfd)))
    fprintf(stderr, "[EAP:KPALV:WARN] truncat pidfile '%s': %s\n",
            "/tmp/cwnu-drcom-eap.pid", strerror(errno));
  ;
  fprintf(kpalvfd, "%d", curpid);
  fflush(kpalvfd);
  if (0 == eap_keep_alive(skfd, skaddr)) {
    fprintf(stderr, "%s: [EAP:KPALV] Server maybe not need keep alive paket.\n",
            format_time());
    ;
    fprintf(stderr, "%s: [EAP:KPALV] Now, keep alive process quit!\n",
            format_time());
    ;
  }
  if (NULL == (kpalvfd = freopen("/tmp/cwnu-drcom-eap.pid", "w+", kpalvfd)))
    fprintf(stderr, "[EAP:KPALV:WARN] truncat pidfile '%s': %s\n",
            "/tmp/cwnu-drcom-eap.pid", strerror(errno));
  ;
  fprintf(kpalvfd, "-1");
  fflush(kpalvfd);
  fclose(kpalvfd);
  return 0;
}


x86 assembly (clang, -O0):
<eap_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdfa(%rip),%rdi
lea    0xe0b(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    12bf <eap_daemon+0xcf>
mov    0x2db7(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rcx
lea    0xdcf(%rip),%rsi
lea    0xdad(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    0xd9f(%rip),%rdi
lea    0xddb(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    12ba <eap_daemon+0xca>
mov    0x2d5c(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f3 <eap_daemon+0x303>
jmp    12bf <eap_daemon+0xcf>
mov    -0x18(%rbp),%rdi
mov    0x2d06(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <fseek@plt>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xd8f(%rip),%rsi
call   1070 <fscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1315 <eap_daemon+0x125>
cmpq   $0xffffffffffffffff,-0x20(%rbp)
je     1315 <eap_daemon+0x125>
mov    -0x20(%rbp),%rdi
mov    0x2cba(%rip),%rax
mov    (%rax),%esi
call   10b0 <kill@plt>
mov    $0x0,%al
call   1080 <setsid@plt>
lea    0xd53(%rip),%rdi
call   1050 <chdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1367 <eap_daemon+0x177>
mov    0x2ca3(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
lea    0xd18(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10a0 <umask@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
lea    0xc7c(%rip),%rdi
lea    0xcb8(%rip),%rsi
call   1060 <freopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    13da <eap_daemon+0x1ea>
mov    0x2c37(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rcx
lea    0xcc1(%rip),%rsi
lea    0xc2d(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xc8a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <fflush@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <eap_keep_alive@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1467 <eap_daemon+0x277>
mov    0x2bc6(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1110 <format_time@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rdx
lea    0xc82(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b9c(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1110 <format_time@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xc91(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdx
lea    0xb8e(%rip),%rdi
lea    0xbca(%rip),%rsi
call   1060 <freopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    14c8 <eap_daemon+0x2d8>
mov    0x2b49(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rcx
lea    0xbd3(%rip),%rsi
lea    0xb3f(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xc4d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eap_daemon>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
lea    0xde8(%rip),%rdi
lea    0xdf9(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1280 <eap_daemon+0x80>
mov    0x2dad(%rip),%r12
movslq (%r12),%rbx
mov    0x2d9a(%rip),%r13
mov    0x0(%r13),%edi
call   1110 <strerror@plt>
lea    0xdcd(%rip),%rsi
lea    0xdab(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xdd7(%rip),%rsi
mov    %rbp,%rdi
call   10f0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1462 <eap_daemon+0x262>
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
lea    0xdd9(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    12c2 <eap_daemon+0xc2>
mov    (%rsp),%rdi
cmp    $0xffffffffffffffff,%rdi
je     12c2 <eap_daemon+0xc2>
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
call   10b0 <kill@plt>
xor    %eax,%eax
call   1080 <setsid@plt>
lea    0xda6(%rip),%rdi
call   1050 <chdir@plt>
test   %rax,%rax
je     1306 <eap_daemon+0x106>
mov    0x2cff(%rip),%rax
movslq (%rax),%rbp
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xd7f(%rip),%rsi
mov    %rbp,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10a0 <umask@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbp
lea    0xce2(%rip),%rdi
lea    0xd1e(%rip),%rsi
mov    %rbx,%rdx
call   1060 <freopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1368 <eap_daemon+0x168>
mov    0x2ca4(%rip),%rax
movslq (%rax),%r12
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xd39(%rip),%rsi
lea    0xca5(%rip),%rdx
mov    %r12,%rdi
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xd04(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   10c0 <fflush@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   10d0 <eap_keep_alive@plt>
test   %rax,%rax
jne    13d7 <eap_daemon+0x1d7>
mov    0x2c45(%rip),%r14
movslq (%r14),%rbp
xor    %eax,%eax
call   1120 <format_time@plt>
lea    0xd0c(%rip),%rsi
mov    %rbp,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
movslq (%r14),%rbp
xor    %eax,%eax
call   1120 <format_time@plt>
lea    0xd27(%rip),%rsi
mov    %rbp,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xc22(%rip),%rdi
lea    0xc5e(%rip),%rsi
mov    %rbx,%rdx
call   1060 <freopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1428 <eap_daemon+0x228>
mov    0x2be4(%rip),%rax
movslq (%rax),%rbp
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc79(%rip),%rsi
lea    0xbe5(%rip),%rdx
mov    %rbp,%rdi
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xcf1(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
mov    %rbx,%rdi
call   10c0 <fflush@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq (%r12),%rbx
mov    0x0(%r13),%edi
call   1110 <strerror@plt>
lea    0xbd0(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1453 <eap_daemon+0x253>

LLVM IR (-O0):
%struct.sockaddr_ll = type { i32 }
@.str = [24 x i8] c"/tmp/cwnu-drcom-eap.pid\00"
@.str.1 = [3 x i8] c"r+\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"[EAP:KPALV] No process pidfile. %s: %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [45 x i8] c"[EAP:KPALV] Detect pid file eror(%s)! quit!\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [3 x i8] c"%d\00"
@SIGKILL = global i32 0
@.str.6 = [2 x i8] c"/\00"
@.str.7 = [21 x i8] c"[EAP:KPALV:WARN] %s\0A\00"
@.str.8 = [43 x i8] c"[EAP:KPALV:WARN] truncat pidfile '%s': %s\0A\00"
@.str.9 = [57 x i8] c"%s: [EAP:KPALV] Server maybe not need keep alive paket.\0A\00"
@.str.10 = [47 x i8] c"%s: [EAP:KPALV] Now, keep alive process quit!\0A\00"
@.str.11 = [3 x i8] c"-1\00"
define i32 @eap_daemon(i32 %0, %struct.sockaddr_ll* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_ll*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
store i32 %0, i32* %4
store %struct.sockaddr_ll* %1, %struct.sockaddr_ll** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* null, %10
br i1 %11, label %12, label %30
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* null, %20
br i1 %21, label %22, label %29
22: ; preds = %12
%23 = load i32, i32* @stderr
%24 = sext i32 %23 to i64
%25 = inttoptr i64 %24 to i32*
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %27)
store i32 -1, i32* %3
br label %108
29: ; preds = %12
br label %30
30: ; preds = %29, %2
%31 = load i32*, i32** %6
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %31, i64 0, i32 %32)
%34 = load i32*, i32** %6
%35 = bitcast i64* %7 to i32*
%36 = call i32 @fscanf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %35)
%37 = icmp eq i32 1, %36
br i1 %37, label %38, label %45
38: ; preds = %30
%39 = load i64, i64* %7
%40 = icmp ne i64 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i64, i64* %7
%43 = load i32, i32* @SIGKILL
%44 = call i32 @kill(i64 %42, i32 %43)
br label %45
45: ; preds = %41, %38, %30
%46 = call i32 (...) @setsid()
%47 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%48 = icmp ne i64 0, %47
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = sext i32 %50 to i64
%52 = inttoptr i64 %51 to i32*
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %49, %45
%57 = call i32 @umask(i32 0)
%58 = call i64 (...) @getpid()
store i64 %58, i64* %8
%59 = load i32*, i32** %6
%60 = call i32* @freopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %59)
store i32* %60, i32** %6
%61 = icmp eq i32* null, %60
br i1 %61, label %62, label %69
62: ; preds = %56
%63 = load i32, i32* @stderr
%64 = sext i32 %63 to i64
%65 = inttoptr i64 %64 to i32*
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %62, %56
%70 = load i32*, i32** %6
%71 = load i64, i64* %8
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 %71)
%73 = load i32*, i32** %6
%74 = call i32 @fflush(i32* %73)
%75 = load i32, i32* %4
%76 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%77 = call i64 @eap_keep_alive(i32 %75, %struct.sockaddr_ll* %76)
%78 = icmp eq i64 0, %77
br i1 %78, label %79, label %90
79: ; preds = %69
%80 = load i32, i32* @stderr
%81 = sext i32 %80 to i64
%82 = inttoptr i64 %81 to i32*
%83 = call i8* (...) @format_time()
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %82, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.9, i64 0, i64 0), i8* %83)
%85 = load i32, i32* @stderr
%86 = sext i32 %85 to i64
%87 = inttoptr i64 %86 to i32*
%88 = call i8* (...) @format_time()
%89 = call i32 (i32*, i8*, ...) @fprintf(i32* %87, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i8* %88)
br label %90
90: ; preds = %79, %69
%91 = load i32*, i32** %6
%92 = call i32* @freopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %91)
store i32* %92, i32** %6
%93 = icmp eq i32* null, %92
br i1 %93, label %94, label %101
94: ; preds = %90
%95 = load i32, i32* @stderr
%96 = sext i32 %95 to i64
%97 = inttoptr i64 %96 to i32*
%98 = load i32, i32* @errno
%99 = call i8* @strerror(i32 %98)
%100 = call i32 (i32*, i8*, ...) @fprintf(i32* %97, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %99)
br label %101
101: ; preds = %94, %90
%102 = load i32*, i32** %6
%103 = call i32 (i32*, i8*, ...) @fprintf(i32* %102, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%104 = load i32*, i32** %6
%105 = call i32 @fflush(i32* %104)
%106 = load i32*, i32** %6
%107 = call i32 @fclose(i32* %106)
store i32 0, i32* %3
br label %108
108: ; preds = %101, %22
%109 = load i32, i32* %3
ret i32 %109
}

LLVM IR (-O2):
%struct.sockaddr_ll = type { i32 }
@.str = [24 x i8] c"/tmp/cwnu-drcom-eap.pid\00"
@.str.1 = [3 x i8] c"r+\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"[EAP:KPALV] No process pidfile. %s: %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [45 x i8] c"[EAP:KPALV] Detect pid file eror(%s)! quit!\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [3 x i8] c"%d\00"
@SIGKILL = global i32 0
@.str.6 = [2 x i8] c"/\00"
@.str.7 = [21 x i8] c"[EAP:KPALV:WARN] %s\0A\00"
@.str.8 = [43 x i8] c"[EAP:KPALV:WARN] truncat pidfile '%s': %s\0A\00"
@.str.9 = [57 x i8] c"%s: [EAP:KPALV] Server maybe not need keep alive paket.\0A\00"
@.str.10 = [47 x i8] c"%s: [EAP:KPALV] Now, keep alive process quit!\0A\00"
@.str.11 = [3 x i8] c"-1\00"
define i32 @eap_daemon(i32 %0, %struct.sockaddr_ll* %1) {
%3 = alloca i64
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %22
15: ; preds = %6
%16 = load i32, i32* @stderr
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i32*
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %20)
br label %89
22: ; preds = %6, %2
%23 = phi i32* [ %13, %6 ], [ %4, %2 ]
%24 = bitcast i64* %3 to i8*
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %23, i64 0, i32 %25)
%27 = bitcast i64* %3 to i32*
%28 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %27)
%29 = icmp eq i32 %28, 1
%30 = load i64, i64* %3
%31 = icmp ne i64 %30, -1
%32 = select i1 %29, i1 %31, i1 false
br i1 %32, label %33, label %36
33: ; preds = %22
%34 = load i32, i32* @SIGKILL
%35 = call i32 @kill(i64 %30, i32 %34)
br label %36
36: ; preds = %33, %22
%37 = call i32 (...) @setsid()
%38 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %47, label %40
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = sext i32 %41 to i64
%43 = inttoptr i64 %42 to i32*
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %40, %36
%48 = call i32 @umask(i32 0)
%49 = call i64 (...) @getpid()
%50 = call i32* @freopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %23)
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %59
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = sext i32 %53 to i64
%55 = inttoptr i64 %54 to i32*
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %52, %47
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 %49)
%61 = call i32 @fflush(i32* %50)
%62 = call i64 @eap_keep_alive(i32 %0, %struct.sockaddr_ll* %1)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %75
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = sext i32 %65 to i64
%67 = inttoptr i64 %66 to i32*
%68 = call i8* (...) @format_time()
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.9, i64 0, i64 0), i8* %68)
%70 = load i32, i32* @stderr
%71 = sext i32 %70 to i64
%72 = inttoptr i64 %71 to i32*
%73 = call i8* (...) @format_time()
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i8* %73)
br label %75
75: ; preds = %64, %59
%76 = call i32* @freopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %50)
%77 = icmp eq i32* %76, null
br i1 %77, label %78, label %85
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = sext i32 %79 to i64
%81 = inttoptr i64 %80 to i32*
%82 = load i32, i32* @errno
%83 = call i8* @strerror(i32 %82)
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %81, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %83)
br label %85
85: ; preds = %78, %75
%86 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i64 2, i64 1, i32* %76)
%87 = call i32 @fflush(i32* %76)
%88 = call i32 @fclose(i32* %76)
br label %89
89: ; preds = %85, %15
%90 = phi i32 [ -1, %15 ], [ 0, %85 ]
ret i32 %90
}