#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 scalar_t__ ulong;
struct stat {
  scalar_t__ st_size;
};
struct sockaddr_nl {
  int dummy;
};
struct flock {
  int /*<<< orphan*/ l_type;
  scalar_t__ l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
};
typedef int /*<<< orphan*/ buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ F_UNLCK;
int /*<<< orphan*/ F_WRLCK;
scalar_t__ LONG_MAX;
scalar_t__ LONG_MIN;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fcntl(int, int /*<<< orphan*/, struct flock *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ memset(char *, int, int);
int open(char *, int, int);
scalar_t__ strtol(char *, char **, int);
int /*<<< orphan*/ talk_to_kernel(int, scalar_t__, struct sockaddr_nl *);
int /*<<< orphan*/ truncate(char *, unsigned long);
void sec_box_load_clean_file(int sockfd, struct sockaddr_nl *pdaddr) {
  FILE *fp = NULL;
  int flck = 0;
  char buff[128];
  int fsz;
  ulong inode;
  flck = open("./sec_box_netclean.lck", O_CREAT | O_RDWR | O_TRUNC, 0666);
  if (flck <= 0)
    return;
  struct flock lck;
  lck.l_type = F_WRLCK;
  lck.l_whence = SEEK_SET;
  lck.l_start = 0;
  lck.l_len = 0;
  if (-1 == fcntl(flck, F_SETLK, &lck))
    goto out;
  fp = fopen("./sec_box_netclean.file", "a+");
  if (!fp)
    goto out;
  struct stat _stat;
  if (-1 == lstat("./sec_box_netclean.file", &_stat) || _stat.st_size == 0)
    goto out;
  char *endptr;
  while (fgets(buff, sizeof(buff), fp)) {
    inode = strtol(buff, &endptr, 10);
    if (inode > LONG_MIN && inode < LONG_MAX)
      talk_to_kernel(sockfd, inode, pdaddr);
    memset(buff, 0x0, sizeof(buff));
  }
  lck.l_type = F_UNLCK;
  fcntl(flck, F_SETLK, &lck);
out:
  if (flck > 0)
    close(flck);
  if (fp > 0) {
    fclose(fp);
    truncate("./sec_box_netclean.file", 0UL);
  }
  return;
}


x86 assembly (clang, -O0):
<sec_box_load_clean_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
mov    0x2e06(%rip),%rax
or     (%rax),%esi
lea    0xe0d(%rip),%rdi
mov    $0x1b6,%edx
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     120f <sec_box_load_clean_file+0x5f>
jmp    13c9 <sec_box_load_clean_file+0x219>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb8(%rbp)
movq   $0x0,-0xc0(%rbp)
movq   $0x0,-0xc8(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdx
call   1030 <fcntl@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    126f <sec_box_load_clean_file+0xbf>
jmp    138e <sec_box_load_clean_file+0x1de>
lea    0xda1(%rip),%rdi
lea    0xdb2(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1296 <sec_box_load_clean_file+0xe6>
jmp    138e <sec_box_load_clean_file+0x1de>
lea    0xd7a(%rip),%rdi
lea    -0xd8(%rbp),%rsi
call   1070 <lstat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     12c6 <sec_box_load_clean_file+0x116>
cmpq   $0x0,-0xd8(%rbp)
jne    12cb <sec_box_load_clean_file+0x11b>
jmp    138e <sec_box_load_clean_file+0x1de>
jmp    12d0 <sec_box_load_clean_file+0x120>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1367 <sec_box_load_clean_file+0x1b7>
lea    -0xa0(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %rax,-0xb0(%rbp)
mov    -0xb0(%rbp),%rax
mov    0x2cac(%rip),%rcx
cmp    (%rcx),%rax
jle    134f <sec_box_load_clean_file+0x19f>
mov    -0xb0(%rbp),%rax
mov    0x2c7d(%rip),%rcx
cmp    (%rcx),%rax
jge    134f <sec_box_load_clean_file+0x19f>
mov    -0x4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   10d0 <talk_to_kernel@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
jmp    12d0 <sec_box_load_clean_file+0x120>
mov    0x2c52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd0(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2c50(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdx
call   1030 <fcntl@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    13a0 <sec_box_load_clean_file+0x1f0>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
cmpq   $0x0,-0x18(%rbp)
jbe    13c4 <sec_box_load_clean_file+0x214>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xc5c(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <truncate@plt>
jmp    13c9 <sec_box_load_clean_file+0x219>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sec_box_load_clean_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    0x2e30(%rip),%rcx
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %rsi,0x8(%rsp)
mov    %edi,%r15d
mov    0x2e0e(%rip),%rcx
or     (%rcx),%eax
lea    0xe15(%rip),%rdi
mov    %eax,%esi
mov    $0x1b6,%edx
call   10b0 <open@plt>
test   %eax,%eax
jle    1362 <sec_box_load_clean_file+0x1b2>
mov    %eax,%r12d
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
mov    %r12d,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1317 <sec_box_load_clean_file+0x167>
lea    0xdcd(%rip),%rdi
lea    0xdde(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1317 <sec_box_load_clean_file+0x167>
mov    %rax,%rbp
lea    0xdae(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1070 <lstat@plt>
cmp    $0xffffffff,%eax
je     1344 <sec_box_load_clean_file+0x194>
cmpq   $0x0,0x10(%rsp)
je     1344 <sec_box_load_clean_file+0x194>
lea    0x40(%rsp),%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1321 <sec_box_load_clean_file+0x171>
lea    0x40(%rsp),%rbx
lea    0x38(%rsp),%r13
mov    0x2d14(%rip),%r14
jmp    12e4 <sec_box_load_clean_file+0x134>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1321 <sec_box_load_clean_file+0x171>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0xa,%edx
call   1090 <strtol@plt>
cmp    (%r14),%rax
jle    12c0 <sec_box_load_clean_file+0x110>
mov    0x2cb0(%rip),%rcx
cmp    (%rcx),%rax
jge    12c0 <sec_box_load_clean_file+0x110>
mov    %r15d,%edi
mov    %rax,%rsi
mov    0x8(%rsp),%rdx
call   10d0 <talk_to_kernel@plt>
jmp    12c0 <sec_box_load_clean_file+0x110>
mov    %r12d,%edi
call   1060 <close@plt>
jmp    1362 <sec_box_load_clean_file+0x1b2>
mov    0x2c98(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2c9b(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
mov    %r12d,%edi
call   1030 <fcntl@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xcbc(%rip),%rdi
xor    %esi,%esi
call   10a0 <truncate@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32 }
%struct.flock = type { i32, i64, i64, i32 }
%struct.stat = type { i64 }
@.str = [23 x i8] c"./sec_box_netclean.lck\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str.1 = [24 x i8] c"./sec_box_netclean.file\00"
@.str.2 = [3 x i8] c"a+\00"
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@F_UNLCK = global i32 0
define void @sec_box_load_clean_file(i32 %0, %struct.sockaddr_nl* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_nl*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca i32
%9 = alloca i64
%10 = alloca %struct.flock
%11 = alloca %struct.stat
%12 = alloca i8*
store i32 %0, i32* %3
store %struct.sockaddr_nl* %1, %struct.sockaddr_nl** %4
store i32* null, i32** %5
store i32 0, i32* %6
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_RDWR
%15 = or i32 %13, %14
%16 = load i32, i32* @O_TRUNC
%17 = or i32 %15, %16
%18 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %17, i32 438)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %2
br label %91
22: ; preds = %2
%23 = load i32, i32* @F_WRLCK
%24 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @SEEK_SET
%26 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 3
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 2
store i64 0, i64* %27
%28 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 1
store i64 0, i64* %28
%29 = load i32, i32* %6
%30 = load i32, i32* @F_SETLK
%31 = call i32 @fcntl(i32 %29, i32 %30, %struct.flock* %10)
%32 = icmp eq i32 -1, %31
br i1 %32, label %33, label %34
33: ; preds = %22
br label %77
34: ; preds = %22
%35 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %35, i32** %5
%36 = load i32*, i32** %5
%37 = icmp ne i32* %36, null
br i1 %37, label %39, label %38
38: ; preds = %34
br label %77
39: ; preds = %34
%40 = call i32 @lstat(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %11)
%41 = icmp eq i32 -1, %40
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%44 = load i64, i64* %43
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42, %39
br label %77
47: ; preds = %42
br label %48
48: ; preds = %68, %47
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%50 = load i32*, i32** %5
%51 = call i64 @fgets(i8* %49, i32 128, i32* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %71
53: ; preds = %48
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%55 = call i64 @strtol(i8* %54, i8** %12, i32 10)
store i64 %55, i64* %9
%56 = load i64, i64* %9
%57 = load i64, i64* @LONG_MIN
%58 = icmp sgt i64 %56, %57
br i1 %58, label %59, label %68
59: ; preds = %53
%60 = load i64, i64* %9
%61 = load i64, i64* @LONG_MAX
%62 = icmp slt i64 %60, %61
br i1 %62, label %63, label %68
63: ; preds = %59
%64 = load i32, i32* %3
%65 = load i64, i64* %9
%66 = load %struct.sockaddr_nl*, %struct.sockaddr_nl** %4
%67 = call i32 @talk_to_kernel(i32 %64, i64 %65, %struct.sockaddr_nl* %66)
br label %68
68: ; preds = %63, %59, %53
%69 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%70 = call i32 @memset(i8* %69, i32 0, i32 128)
br label %48
71: ; preds = %48
%72 = load i32, i32* @F_UNLCK
%73 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 0
store i32 %72, i32* %73
%74 = load i32, i32* %6
%75 = load i32, i32* @F_SETLK
%76 = call i32 @fcntl(i32 %74, i32 %75, %struct.flock* %10)
br label %77
77: ; preds = %71, %46, %38, %33
%78 = load i32, i32* %6
%79 = icmp sgt i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i32, i32* %6
%82 = call i32 @close(i32 %81)
br label %83
83: ; preds = %80, %77
%84 = load i32*, i32** %5
%85 = icmp ugt i32* %84, null
br i1 %85, label %86, label %90
86: ; preds = %83
%87 = load i32*, i32** %5
%88 = call i32 @fclose(i32* %87)
%89 = call i32 @truncate(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 0)
br label %90
90: ; preds = %86, %83
br label %91
91: ; preds = %90, %21
ret void
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32 }
%struct.flock = type { i32, i64, i64, i32 }
%struct.stat = type { i64 }
@.str = [23 x i8] c"./sec_box_netclean.lck\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str.1 = [24 x i8] c"./sec_box_netclean.file\00"
@.str.2 = [3 x i8] c"a+\00"
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@F_UNLCK = global i32 0
define void @sec_box_load_clean_file(i32 %0, %struct.sockaddr_nl* %1) {
%3 = alloca [128 x i8]
%4 = alloca %struct.flock
%5 = alloca %struct.stat
%6 = alloca i8*
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @O_CREAT
%9 = load i32, i32* @O_RDWR
%10 = or i32 %9, %8
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %12, i32 438)
%14 = icmp slt i32 %13, 1
br i1 %14, label %63, label %15
15: ; preds = %2
%16 = bitcast %struct.flock* %4 to i8*
%17 = load i32, i32* @F_WRLCK
%18 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @SEEK_SET
%20 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 3
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 1
%22 = bitcast i64* %21 to i8*
%23 = load i32, i32* @F_SETLK
%24 = call i32 @fcntl(i32 %13, i32 %23, %struct.flock* %4)
%25 = icmp eq i32 %24, -1
br i1 %25, label %52, label %26
26: ; preds = %15
%27 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %52, label %29
29: ; preds = %26
%30 = call i32 @lstat(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %5)
%31 = icmp eq i32 %30, -1
%32 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%33 = load i64, i64* %32
%34 = icmp eq i64 %33, 0
%35 = select i1 %31, i1 true, i1 %34
br i1 %35, label %58, label %36
36: ; preds = %29
%37 = call i64 @fgets(i8* %7, i32 128, i32* %27)
%38 = icmp eq i64 %37, 0
br i1 %38, label %54, label %39
39: ; preds = %36, %48
%40 = call i64 @strtol(i8* %7, i8** %6, i32 10)
%41 = load i64, i64* @LONG_MIN
%42 = icmp sgt i64 %40, %41
%43 = load i64, i64* @LONG_MAX
%44 = icmp slt i64 %40, %43
%45 = select i1 %42, i1 %44, i1 false
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @talk_to_kernel(i32 %0, i64 %40, %struct.sockaddr_nl* %1)
br label %48
48: ; preds = %46, %39
%49 = call i32 @memset(i8* %7, i32 0, i32 128)
%50 = call i64 @fgets(i8* %7, i32 128, i32* %27)
%51 = icmp eq i64 %50, 0
br i1 %51, label %54, label %39
52: ; preds = %15, %26
%53 = call i32 @close(i32 %13)
br label %62
54: ; preds = %48, %36
%55 = load i32, i32* @F_UNLCK
store i32 %55, i32* %18
%56 = load i32, i32* @F_SETLK
%57 = call i32 @fcntl(i32 %13, i32 %56, %struct.flock* %4)
br label %58
58: ; preds = %29, %54
%59 = call i32 @close(i32 %13)
%60 = call i32 @fclose(i32* %27)
%61 = call i32 @truncate(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 0)
br label %62
62: ; preds = %52, %58
br label %63
63: ; preds = %2, %62
ret void
}