#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_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ clnt_addr;

/* Variables and functions */
scalar_t__ EINTR;
int EXIT_SUCCESS;
scalar_t__ errno;
int /*<<< orphan*/ handle_request(char *, struct sockaddr_in *, int);
int /*<<< orphan*/ narrate(char *, char *, struct sockaddr_in *);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int setup();
int main(void) {
  struct sockaddr_in clnt_addr;
  socklen_t addrlen = sizeof(clnt_addr);
  int ret;
  char buf[128];
  int sock_fd = setup();
  while (true) {
    ret =
        recvfrom(sock_fd, buf, 128, 0, (struct sockaddr *)&clnt_addr, &addrlen);
    if (ret != -1) {
      buf[ret] = '\0';
      narrate("GOT:", buf, &clnt_addr);
      handle_request(buf, &clnt_addr, addrlen);
    } else {
      if (errno != EINTR)
        perror("recvfrom");
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
mov    $0x0,%al
call   1070 <setup@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%edi
lea    -0x90(%rbp),%rsi
lea    -0x8(%rbp),%r8
mov    $0x80,%edx
xor    %ecx,%ecx
lea    -0xc(%rbp),%r9
call   1050 <recvfrom@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
je     11df <main+0x8f>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rsi
lea    0xe42(%rip),%rdi
lea    -0x8(%rbp),%rdx
call   1030 <narrate@plt>
lea    -0x90(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    -0x8(%rbp),%rsi
call   1040 <handle_request@plt>
jmp    120a <main+0xba>
mov    0x2dfa(%rip),%rax
mov    (%rax),%rax
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%rax
je     1205 <main+0xb5>
lea    0xe05(%rip),%rdi
call   1060 <perror@plt>
jmp    120a <main+0xba>
jmp    1176 <main+0x26>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
movl   $0x4,0x4(%rsp)
xor    %eax,%eax
call   1070 <setup@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rbp
lea    0x4(%rsp),%r15
mov    0x2e4f(%rip),%r12
lea    0xe70(%rip),%r13
jmp    11c4 <main+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <narrate@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <handle_request@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    %r15,%r9
call   1050 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x50>
mov    0x2df8(%rip),%rax
mov    (%rax),%rax
cmp    (%r12),%rax
je     11c4 <main+0x74>
lea    0xe0d(%rip),%rdi
call   1060 <perror@plt>
jmp    11c4 <main+0x74>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"GOT:\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [9 x i8] c"recvfrom\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %3
%7 = call i32 (...) @setup()
store i32 %7, i32* %6
br label %8
8: ; preds = %0, %31
%9 = load i32, i32* %6
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%11 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%12 = call i32 @recvfrom(i32 %9, i8* %10, i32 128, i32 0, %struct.sockaddr* %11, i32* %3)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %24
15: ; preds = %8
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%20 = call i32 @narrate(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %19, %struct.sockaddr_in* %2)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* %3
%23 = call i32 @handle_request(i8* %21, %struct.sockaddr_in* %2, i32 %22)
br label %31
24: ; preds = %8
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
br label %31
31: ; preds = %30, %15
br label %8
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"GOT:\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [9 x i8] c"recvfrom\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (...) @setup()
%8 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %9
9: ; preds = %22, %0
%10 = call i32 @recvfrom(i32 %7, i8* %6, i32 128, i32 0, %struct.sockaddr* %8, i32* %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 @narrate(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6, %struct.sockaddr_in* %1)
%16 = load i32, i32* %2
%17 = call i32 @handle_request(i8* %6, %struct.sockaddr_in* %1, i32 %16)
br label %22
18: ; preds = %9
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18, %23, %12
br label %9
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %22
}