#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*/ uint8_t;
struct nlmsghdr {
  int dummy;
};
typedef int /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ handle_message(struct nlmsghdr *, int /*<<< orphan*/);
int /*<<< orphan*/ recv_msg(int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, int,
                          int /*<<< orphan*/);
void mainloop(int fd) {
  uint8_t buffer[4096];
  ssize_t ret;
  while (1) {
    if ((ret = recv_msg(fd, buffer, sizeof(buffer))) < 0) {
      do {
        syslog(LOG_ERR,
               "%s(%d): "
               "%s",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/Ongy/ip-notify/refs/heads/"
               "master/src/ip-notify.c",
               153, strerror(errno));
        exit(-1);
      } while (0);
    }
    handle_message((struct nlmsghdr *)buffer, ret);
  }
}


x86 assembly (clang, -O0):
<mainloop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x4010(%rbp),%rsi
mov    $0x4000,%edx
call   1030 <recv_msg@plt>
mov    %eax,-0x4014(%rbp)
cmp    $0x0,%eax
jge    11ce <mainloop+0x7e>
jmp    1186 <mainloop+0x36>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4018(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x4018(%rbp),%edi
mov    %eax,%r8d
lea    0xe4d(%rip),%rsi
lea    0xe51(%rip),%rdx
mov    $0x99,%ecx
call   1050 <syslog@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    -0x4010(%rbp),%rdi
mov    -0x4014(%rbp),%esi
call   1040 <handle_message@plt>
jmp    115e <mainloop+0xe>

x86 assembly (clang, -O2):
<mainloop>:
push   %rbp
push   %rbx
sub    $0x4008,%rsp
mov    %edi,%ebp
mov    %rsp,%rsi
mov    $0x4000,%edx
call   1030 <recv_msg@plt>
test   %eax,%eax
js     118d <mainloop+0x3d>
mov    %rsp,%rbx
nop
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <handle_message@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4000,%edx
call   1030 <recv_msg@plt>
test   %eax,%eax
jns    1170 <mainloop+0x20>
mov    0x2e3c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe55(%rip),%rsi
lea    0xe59(%rip),%rdx
mov    %ebx,%edi
mov    $0x99,%ecx
mov    %eax,%r8d
call   1050 <syslog@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
@LOG_ERR = global i32 0
@.str = [11 x i8] c"%s(%d): %s\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ongy/ip-notify/refs/heads/master/src/ip-notify.c\00"
@errno = global i32 0
define void @mainloop(i32 %0) {
%2 = alloca i32
%3 = alloca [4096 x i32]
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %1, %18
%6 = load i32, i32* %2
%7 = getelementptr inbounds [4096 x i32], [4096 x i32]* %3, i64 0, i64 0
%8 = call i32 @recv_msg(i32 %6, i32* %7, i32 16384)
store i32 %8, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %5
br label %11
11: ; preds = %10
%12 = load i32, i32* @LOG_ERR
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 @syslog(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 153, i32 %14)
%16 = call i32 @exit(i32 -1)
unreachable
17: ; No predecessors!
br label %18
18: ; preds = %17, %5
%19 = getelementptr inbounds [4096 x i32], [4096 x i32]* %3, i64 0, i64 0
%20 = bitcast i32* %19 to %struct.nlmsghdr*
%21 = load i32, i32* %4
%22 = call i32 @handle_message(%struct.nlmsghdr* %20, i32 %21)
br label %5
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
@LOG_ERR = global i32 0
@.str = [11 x i8] c"%s(%d): %s\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ongy/ip-notify/refs/heads/master/src/ip-notify.c\00"
@errno = global i32 0
define void @mainloop(i32 %0) {
%2 = alloca [4096 x i32]
%3 = bitcast [4096 x i32]* %2 to i8*
%4 = getelementptr inbounds [4096 x i32], [4096 x i32]* %2, i64 0, i64 0
%5 = call i32 @recv_msg(i32 %0, i32* %4, i32 16384)
%6 = icmp slt i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = bitcast [4096 x i32]* %2 to %struct.nlmsghdr*
br label %15
9: ; preds = %15, %1
%10 = load i32, i32* @LOG_ERR
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 @syslog(i32 %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 153, i32 %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %7, %15
%16 = phi i32 [ %5, %7 ], [ %18, %15 ]
%17 = call i32 @handle_message(%struct.nlmsghdr* %8, i32 %16)
%18 = call i32 @recv_msg(i32 %0, i32* %4, i32 16384)
%19 = icmp slt i32 %18, 0
br i1 %19, label %9, label %15
}