#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 /*<<< orphan*/ sll_protocol;
  int /*<<< orphan*/ ifr_ifindex;
  int /*<<< orphan*/ sll_ifindex;
  int /*<<< orphan*/ sll_family;
  int /*<<< orphan*/ ifr_name;
};
struct sockaddr {
  int dummy;
};
struct ifreq {
  int /*<<< orphan*/ sll_protocol;
  int /*<<< orphan*/ ifr_ifindex;
  int /*<<< orphan*/ sll_ifindex;
  int /*<<< orphan*/ sll_family;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ ETH_P_PAE;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int /*<<< orphan*/ PF_PACKET;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ SOCK_RAW;
int bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, ...);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, struct sockaddr_ll *);
int /*<<< orphan*/ memset(struct sockaddr_ll *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int socket_eapol_init(char *ifname, struct sockaddr_ll *psll) {
  struct ifreq ifr;
  int sockfd;
  int sockopts, sockerr, retval;
  if (ifname == NULL || psll == NULL) {
    fprintf(stderr, "[%s][%d] param is null\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/weiqiangdragonite/blog_tmp/refs/heads/"
            "master/unix_linux/802.1x/mytest/raw_main.c",
            812);
    return -1;
  }
  memset(psll, 0, sizeof(struct sockaddr_ll));
  memset(&ifr, 0, sizeof(ifr));
  sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
  if (sockfd < 0) {
    fprintf(stderr, "[%s][%d] socket() error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/weiqiangdragonite/blog_tmp/refs/heads/"
            "master/unix_linux/802.1x/mytest/raw_main.c",
            823, strerror(errno));
    return -1;
  }
  strcpy((char *)&ifr.ifr_name, ifname);
  retval = ioctl(sockfd, SIOCGIFINDEX, &ifr);
  if (retval < 0) {
    fprintf(stderr, "[%s][%d] ioctl() error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/weiqiangdragonite/blog_tmp/refs/heads/"
            "master/unix_linux/802.1x/mytest/raw_main.c",
            833, strerror(errno));
    close(sockfd);
    return -1;
  }
  psll->sll_family = PF_PACKET;
  psll->sll_ifindex = ifr.ifr_ifindex;
  psll->sll_protocol = htons(ETH_P_PAE);
  retval =
      bind(sockfd, (const struct sockaddr *)psll, sizeof(struct sockaddr_ll));
  if (retval < 0) {
    fprintf(stderr, "[%s][%d] bind() error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/weiqiangdragonite/blog_tmp/refs/heads/"
            "master/unix_linux/802.1x/mytest/raw_main.c",
            846, strerror(errno));
    close(sockfd);
    return -1;
  }
  sockopts = fcntl(sockfd, F_GETFL, 0);
  if (sockopts < 0) {
    fprintf(stderr, "[%s][%d] fcntl() error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/weiqiangdragonite/blog_tmp/refs/heads/"
            "master/unix_linux/802.1x/mytest/raw_main.c",
            856, strerror(errno));
    close(sockfd);
    return -1;
  }
  sockerr = fcntl(sockfd, F_SETFL, sockopts | O_NONBLOCK);
  if (sockerr < 0) {
    fprintf(stderr, "[%s][%d] fcntl() error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/weiqiangdragonite/blog_tmp/refs/heads/"
            "master/unix_linux/802.1x/mytest/raw_main.c",
            864, strerror(errno));
    close(sockfd);
    return -1;
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<socket_eapol_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c6 <socket_eapol_init+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    11f5 <socket_eapol_init+0x55>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
lea    0xe3b(%rip),%rdx
mov    $0x32c,%ecx
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14a4 <socket_eapol_init+0x304>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%esi
mov    %eax,%edx
call   10c0 <socket@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    129b <socket_eapol_init+0xfb>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%r8
lea    0xe47(%rip),%rsi
lea    0xd95(%rip),%rdx
mov    $0x337,%ecx
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14a4 <socket_eapol_init+0x304>
lea    -0x30(%rbp),%rdi
add    $0x10,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x34(%rbp),%edi
mov    0x2ce2(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <ioctl@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    131c <socket_eapol_init+0x17c>
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%r8
lea    0xdeb(%rip),%rsi
lea    0xd1c(%rip),%rdx
mov    $0x341,%ecx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14a4 <socket_eapol_init+0x304>
mov    0x2ccd(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x14,%edx
call   10a0 <bind@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    13b8 <socket_eapol_init+0x218>
mov    0x2c4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%r8
lea    0xd6b(%rip),%rsi
lea    0xc80(%rip),%rdx
mov    $0x34e,%ecx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14a4 <socket_eapol_init+0x304>
mov    -0x34(%rbp),%edi
mov    0x2be6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    1426 <socket_eapol_init+0x286>
mov    0x2be1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2bc5(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%r8
lea    0xd18(%rip),%rsi
lea    0xc12(%rip),%rdx
mov    $0x358,%ecx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14a4 <socket_eapol_init+0x304>
mov    -0x34(%rbp),%edi
mov    0x2b88(%rip),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%edx
mov    0x2ba4(%rip),%rax
or     (%rax),%edx
call   1040 <fcntl@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    149e <socket_eapol_init+0x2fe>
mov    0x2b69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2b4d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,%r8
lea    0xca0(%rip),%rsi
lea    0xb9a(%rip),%rdx
mov    $0x360,%ecx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14a4 <socket_eapol_init+0x304>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_eapol_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     12ec <socket_eapol_init+0x14c>
mov    %rsi,%r15
test   %rsi,%rsi
je     12ec <socket_eapol_init+0x14c>
mov    %rdi,%rbp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    0x2e05(%rip),%r12
mov    (%r12),%r14d
mov    0x2de2(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc9(%rip),%r13
mov    0x0(%r13),%edi
call   1050 <htons@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     1314 <socket_eapol_init+0x174>
mov    %eax,%r14d
lea    0x10(%rsp),%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r14d,%edi
call   1070 <ioctl@plt>
test   %eax,%eax
js     134f <socket_eapol_init+0x1af>
mov    (%r12),%eax
mov    %eax,0xc(%r15)
mov    0x4(%rsp),%eax
mov    %eax,0x8(%r15)
mov    0x0(%r13),%edi
call   1050 <htons@plt>
mov    %eax,(%r15)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x14,%edx
call   10a0 <bind@plt>
test   %eax,%eax
js     137d <socket_eapol_init+0x1dd>
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
test   %eax,%eax
js     13ab <socket_eapol_init+0x20b>
mov    0x2d1a(%rip),%rcx
mov    (%rcx),%esi
mov    0x2d39(%rip),%rcx
or     (%rcx),%eax
mov    %r14d,%edi
mov    %eax,%edx
call   1040 <fcntl@plt>
test   %eax,%eax
jns    13ef <socket_eapol_init+0x24f>
mov    0x2cfe(%rip),%rax
mov    (%rax),%ebx
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe3e(%rip),%rsi
lea    0xd38(%rip),%rdx
mov    %ebx,%edi
mov    $0x360,%ecx
jmp    13d7 <socket_eapol_init+0x237>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
lea    0xd04(%rip),%rsi
lea    0xd15(%rip),%rdx
mov    $0x32c,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    13e9 <socket_eapol_init+0x249>
mov    0x2ca5(%rip),%rax
mov    (%rax),%ebx
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd91(%rip),%rsi
lea    0xcdf(%rip),%rdx
mov    %ebx,%edi
mov    $0x337,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    13e9 <socket_eapol_init+0x249>
mov    0x2c6a(%rip),%rax
mov    (%rax),%ebx
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd73(%rip),%rsi
lea    0xca4(%rip),%rdx
mov    %ebx,%edi
mov    $0x341,%ecx
jmp    13d7 <socket_eapol_init+0x237>
mov    0x2c3c(%rip),%rax
mov    (%rax),%ebx
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd61(%rip),%rsi
lea    0xc76(%rip),%rdx
mov    %ebx,%edi
mov    $0x34e,%ecx
jmp    13d7 <socket_eapol_init+0x237>
mov    0x2c0e(%rip),%rax
mov    (%rax),%ebx
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd4e(%rip),%rsi
lea    0xc48(%rip),%rdx
mov    %ebx,%edi
mov    $0x358,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14d,%edi
call   1080 <close@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_ll = type { i32, i32, i32, i32, i32 }
%struct.ifreq = type { i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"[%s][%d] param is null\0A\00"
@.str.1 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/weiqiangdragonite/blog_tmp/refs/heads/master/unix_linux/802.1x/mytest/raw_main.c\00"
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_PAE = global i32 0
@.str.2 = [29 x i8] c"[%s][%d] socket() error: %s\0A\00"
@errno = global i32 0
@SIOCGIFINDEX = global i32 0
@.str.3 = [28 x i8] c"[%s][%d] ioctl() error: %s\0A\00"
@.str.4 = [27 x i8] c"[%s][%d] bind() error: %s\0A\00"
@F_GETFL = global i32 0
@.str.5 = [28 x i8] c"[%s][%d] fcntl() error: %s\0A\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @socket_eapol_init(i8* %0, %struct.sockaddr_ll* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_ll*
%6 = alloca %struct.ifreq
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store %struct.sockaddr_ll* %1, %struct.sockaddr_ll** %5
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%15 = icmp eq %struct.sockaddr_ll* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13, %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 812)
store i32 -1, i32* %3
br label %110
19: ; preds = %13
%20 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%21 = call i32 @memset(%struct.sockaddr_ll* %20, i32 0, i32 20)
%22 = bitcast %struct.ifreq* %6 to %struct.sockaddr_ll*
%23 = call i32 @memset(%struct.sockaddr_ll* %22, i32 0, i32 20)
%24 = load i32, i32* @PF_PACKET
%25 = load i32, i32* @SOCK_RAW
%26 = load i32, i32* @ETH_P_PAE
%27 = call i32 @htons(i32 %26)
%28 = call i32 @socket(i32 %24, i32 %25, i32 %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %19
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 823, i8* %34)
store i32 -1, i32* %3
br label %110
36: ; preds = %19
%37 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 4
%38 = bitcast i32* %37 to i8*
%39 = load i8*, i8** %4
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i32, i32* %7
%42 = load i32, i32* @SIOCGIFINDEX
%43 = bitcast %struct.ifreq* %6 to %struct.sockaddr_ll*
%44 = call i32 @ioctl(i32 %41, i32 %42, %struct.sockaddr_ll* %43)
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %36
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 833, i8* %50)
%52 = load i32, i32* %7
%53 = call i32 @close(i32 %52)
store i32 -1, i32* %3
br label %110
54: ; preds = %36
%55 = load i32, i32* @PF_PACKET
%56 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%57 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %56, i32 0, i32 3
store i32 %55, i32* %57
%58 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%59 = load i32, i32* %58
%60 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%61 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %60, i32 0, i32 2
store i32 %59, i32* %61
%62 = load i32, i32* @ETH_P_PAE
%63 = call i32 @htons(i32 %62)
%64 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%65 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %64, i32 0, i32 0
store i32 %63, i32* %65
%66 = load i32, i32* %7
%67 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %5
%68 = bitcast %struct.sockaddr_ll* %67 to %struct.sockaddr*
%69 = call i32 @bind(i32 %66, %struct.sockaddr* %68, i32 20)
store i32 %69, i32* %10
%70 = load i32, i32* %10
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %79
72: ; preds = %54
%73 = load i32, i32* @stderr
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 846, i8* %75)
%77 = load i32, i32* %7
%78 = call i32 @close(i32 %77)
store i32 -1, i32* %3
br label %110
79: ; preds = %54
%80 = load i32, i32* %7
%81 = load i32, i32* @F_GETFL
%82 = call i32 @fcntl(i32 %80, i32 %81, i32 0)
store i32 %82, i32* %8
%83 = load i32, i32* %8
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %92
85: ; preds = %79
%86 = load i32, i32* @stderr
%87 = load i32, i32* @errno
%88 = call i8* @strerror(i32 %87)
%89 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 856, i8* %88)
%90 = load i32, i32* %7
%91 = call i32 @close(i32 %90)
store i32 -1, i32* %3
br label %110
92: ; preds = %79
%93 = load i32, i32* %7
%94 = load i32, i32* @F_SETFL
%95 = load i32, i32* %8
%96 = load i32, i32* @O_NONBLOCK
%97 = or i32 %95, %96
%98 = call i32 @fcntl(i32 %93, i32 %94, i32 %97)
store i32 %98, i32* %9
%99 = load i32, i32* %9
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %108
101: ; preds = %92
%102 = load i32, i32* @stderr
%103 = load i32, i32* @errno
%104 = call i8* @strerror(i32 %103)
%105 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 864, i8* %104)
%106 = load i32, i32* %7
%107 = call i32 @close(i32 %106)
store i32 -1, i32* %3
br label %110
108: ; preds = %92
%109 = load i32, i32* %7
store i32 %109, i32* %3
br label %110
110: ; preds = %108, %101, %85, %72, %47, %31, %16
%111 = load i32, i32* %3
ret i32 %111
}

LLVM IR (-O2):
%struct.sockaddr_ll = type { i32, i32, i32, i32, i32 }
%struct.ifreq = type { i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"[%s][%d] param is null\0A\00"
@.str.1 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/weiqiangdragonite/blog_tmp/refs/heads/master/unix_linux/802.1x/mytest/raw_main.c\00"
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_PAE = global i32 0
@.str.2 = [29 x i8] c"[%s][%d] socket() error: %s\0A\00"
@errno = global i32 0
@SIOCGIFINDEX = global i32 0
@.str.3 = [28 x i8] c"[%s][%d] ioctl() error: %s\0A\00"
@.str.4 = [27 x i8] c"[%s][%d] bind() error: %s\0A\00"
@F_GETFL = global i32 0
@.str.5 = [28 x i8] c"[%s][%d] fcntl() error: %s\0A\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @socket_eapol_init(i8* %0, %struct.sockaddr_ll* %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = icmp eq i8* %0, null
%6 = icmp eq %struct.sockaddr_ll* %1, null
%7 = or i1 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 812)
br label %79
11: ; preds = %2
%12 = tail call i32 @memset(%struct.sockaddr_ll* %1, i32 0, i32 20)
%13 = bitcast %struct.ifreq* %3 to %struct.sockaddr_ll*
%14 = call i32 @memset(%struct.sockaddr_ll* %13, i32 0, i32 20)
%15 = load i32, i32* @PF_PACKET
%16 = load i32, i32* @SOCK_RAW
%17 = load i32, i32* @ETH_P_PAE
%18 = call i32 @htons(i32 %17)
%19 = call i32 @socket(i32 %15, i32 %16, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %11
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 823, i8* %24)
br label %79
26: ; preds = %11
%27 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 4
%28 = bitcast i32* %27 to i8*
%29 = call i32 @strcpy(i8* %28, i8* %0)
%30 = load i32, i32* @SIOCGIFINDEX
%31 = call i32 @ioctl(i32 %19, i32 %30, %struct.sockaddr_ll* %13)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 833, i8* %36)
%38 = call i32 @close(i32 %19)
br label %79
39: ; preds = %26
%40 = load i32, i32* @PF_PACKET
%41 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 3
store i32 %40, i32* %41
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 2
store i32 %43, i32* %44
%45 = load i32, i32* @ETH_P_PAE
%46 = call i32 @htons(i32 %45)
%47 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %1, i64 0, i32 0
store i32 %46, i32* %47
%48 = bitcast %struct.sockaddr_ll* %1 to %struct.sockaddr*
%49 = call i32 @bind(i32 %19, %struct.sockaddr* %48, i32 20)
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %57
51: ; preds = %39
%52 = load i32, i32* @stderr
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 846, i8* %54)
%56 = call i32 @close(i32 %19)
br label %79
57: ; preds = %39
%58 = load i32, i32* @F_GETFL
%59 = call i32 @fcntl(i32 %19, i32 %58, i32 0)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %57
%62 = load i32, i32* @stderr
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 856, i8* %64)
%66 = call i32 @close(i32 %19)
br label %79
67: ; preds = %57
%68 = load i32, i32* @F_SETFL
%69 = load i32, i32* @O_NONBLOCK
%70 = or i32 %69, %59
%71 = call i32 @fcntl(i32 %19, i32 %68, i32 %70)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %67
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = call i8* @strerror(i32 %75)
%77 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 864, i8* %76)
%78 = call i32 @close(i32 %19)
br label %79
79: ; preds = %67, %73, %61, %51, %33, %21, %8
%80 = phi i32 [ -1, %8 ], [ -1, %21 ], [ -1, %33 ], [ -1, %51 ], [ -1, %61 ], [ -1, %73 ], [ %19, %67 ]
ret i32 %80
}