#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*/ client_addr;

/* Variables and functions */
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(int ac, char *av[]) {
  struct sockaddr_in client_addr;
  socklen_t addrlen = sizeof(client_addr);
  char buf[128];
  int ret;
  int sock;
  sock = setup();
  while (1) {
    addrlen = sizeof(client_addr);
    ret =
        recvfrom(sock, buf, 128, 0, (struct sockaddr *)&client_addr, &addrlen);
    if (ret != -1) {
      buf[ret] = '\0';
      narrate("GOT:", buf, &client_addr);
      handle_request(buf, &client_addr, addrlen);
    } else {
      perror("recvfrom");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <setup@plt>
mov    %eax,-0xa8(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    -0xa8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x80,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1050 <recvfrom@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0xffffffff,-0xa4(%rbp)
je     11f6 <main+0xa6>
movslq -0xa4(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rsi
lea    0xe2b(%rip),%rdi
lea    -0x18(%rbp),%rdx
call   1030 <narrate@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1040 <handle_request@plt>
jmp    1202 <main+0xb2>
lea    0xe08(%rip),%rdi
call   1060 <perror@plt>
jmp    117d <main+0x2d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
xor    %eax,%eax
call   1070 <setup@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rbp
lea    0x4(%rsp),%r15
lea    0xe84(%rip),%r12
lea    0xe78(%rip),%r13
jmp    11b4 <main+0x64>
nopw   0x0(%rax,%rax,1)
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>
movl   $0x4,0x4(%rsp)
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    1190 <main+0x40>
mov    %r12,%rdi
call   1060 <perror@plt>
jmp    11b4 <main+0x64>

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

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