#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 {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ SIGALRM;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGQUIT;
unsigned int alarm(unsigned int);
scalar_t__ errno;
int /*<<< orphan*/ handle_request(char *, struct sockaddr *, int);
int /*<<< orphan*/ narrate(char *, char *, struct sockaddr *);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int setup();
int /*<<< orphan*/ signal(int /*<<< orphan*/, void (*)(int));
int main(int ac, char *av[]) {
  struct sockaddr client_addr;
  socklen_t addrlen;
  char buf[128];
  int value_from_socket, socket;
  void ticket_reclaim();
  void show_tickets_up(int);
  void show_tickets_quit(int);
  unsigned time_left;
  socket = setup();
  signal(SIGALRM, ticket_reclaim);
  signal(SIGHUP, show_tickets_up);
  signal(SIGQUIT, show_tickets_quit);
  alarm(5);
  while (1) {
    addrlen = sizeof(client_addr);
    value_from_socket = recvfrom(socket, buf, 128, 0,
                                 (struct sockaddr *)&client_addr, &addrlen);
    if (value_from_socket != -1) {
      buf[value_from_socket] = '\0';
      narrate("GOT:", buf, &client_addr);
      time_left = alarm(0);
      handle_request(buf, &client_addr, addrlen);
      alarm(time_left);
    } else if (errno != EINTR) {
      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)
mov    $0x0,%al
call   1090 <setup@plt>
mov    %eax,-0xa8(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e1a(%rip),%rsi
call   1050 <signal@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    0x2de5(%rip),%rsi
call   1050 <signal@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    0x2dd8(%rip),%rsi
call   1050 <signal@plt>
mov    $0x5,%edi
call   1040 <alarm@plt>
movl   $0x4,-0x1c(%rbp)
mov    -0xa8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
lea    -0x18(%rbp),%r8
lea    -0x1c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0xffffffff,-0xa4(%rbp)
je     1270 <main+0x100>
movslq -0xa4(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rsi
lea    0xdc9(%rip),%rdi
lea    -0x18(%rbp),%rdx
call   1030 <narrate@plt>
xor    %edi,%edi
call   1040 <alarm@plt>
mov    %eax,-0xac(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1060 <handle_request@plt>
mov    -0xac(%rbp),%edi
call   1040 <alarm@plt>
jmp    129b <main+0x12b>
mov    0x2d51(%rip),%rax
mov    (%rax),%rax
mov    0x2d37(%rip),%rcx
cmp    (%rcx),%rax
je     1296 <main+0x126>
lea    0xd74(%rip),%rdi
call   1080 <perror@plt>
jmp    129b <main+0x12b>
jmp    11df <main+0x6f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
xor    %eax,%eax
call   1090 <setup@plt>
mov    %eax,%r14d
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x2e25(%rip),%rsi
call   1050 <signal@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rsi
call   1050 <signal@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    0x2de3(%rip),%rsi
call   1050 <signal@plt>
mov    $0x5,%edi
call   1040 <alarm@plt>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rbp
lea    0x4(%rsp),%r15
lea    0xe16(%rip),%r13
jmp    1226 <main+0xb6>
nopl   0x0(%rax)
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <narrate@plt>
xor    %edi,%edi
call   1040 <alarm@plt>
mov    %eax,%r12d
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <handle_request@plt>
mov    %r12d,%edi
call   1040 <alarm@plt>
movl   $0x4,0x4(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    %r15,%r9
call   1070 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    11f0 <main+0x80>
mov    0x2d76(%rip),%rax
mov    (%rax),%rax
mov    0x2d5c(%rip),%rcx
cmp    (%rcx),%rax
je     1226 <main+0xb6>
lea    0xd9d(%rip),%rdi
call   1080 <perror@plt>
jmp    1226 <main+0xb6>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@SIGALRM = global i32 0
@SIGHUP = global i32 0
@SIGQUIT = global i32 0
@.str = [5 x i8] c"GOT:\00"
@errno = global i64 0
@EINTR = global i64 0
@.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
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (...) @setup()
store i32 %12, i32* %10
%13 = load i32, i32* @SIGALRM
%14 = call i32 @signal(i32 %13, void (i32)* bitcast (void (...)* @ticket_reclaim to void (i32)*))
%15 = load i32, i32* @SIGHUP
%16 = call i32 @signal(i32 %15, void (i32)* @show_tickets_up)
%17 = load i32, i32* @SIGQUIT
%18 = call i32 @signal(i32 %17, void (i32)* @show_tickets_quit)
%19 = call i32 @alarm(i32 5)
br label %20
20: ; preds = %2, %45
store i32 4, i32* %7
%21 = load i32, i32* %10
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%23 = call i32 @recvfrom(i32 %21, i8* %22, i32 128, i32 0, %struct.sockaddr* %6, i32* %7)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %38
26: ; preds = %20
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%31 = call i32 @narrate(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %30, %struct.sockaddr* %6)
%32 = call i32 @alarm(i32 0)
store i32 %32, i32* %11
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%34 = load i32, i32* %7
%35 = call i32 @handle_request(i8* %33, %struct.sockaddr* %6, i32 %34)
%36 = load i32, i32* %11
%37 = call i32 @alarm(i32 %36)
br label %45
38: ; preds = %20
%39 = load i64, i64* @errno
%40 = load i64, i64* @EINTR
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
br label %45
45: ; preds = %44, %26
br label %20
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@SIGALRM = global i32 0
@SIGHUP = global i32 0
@SIGQUIT = global i32 0
@.str = [5 x i8] c"GOT:\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [9 x i8] c"recvfrom\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = bitcast %struct.sockaddr* %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 = load i32, i32* @SIGALRM
%11 = tail call i32 @signal(i32 %10, void (i32)* bitcast (void (...)* @ticket_reclaim to void (i32)*))
%12 = load i32, i32* @SIGHUP
%13 = tail call i32 @signal(i32 %12, void (i32)* @show_tickets_up)
%14 = load i32, i32* @SIGQUIT
%15 = tail call i32 @signal(i32 %14, void (i32)* @show_tickets_quit)
%16 = tail call i32 @alarm(i32 5)
br label %17
17: ; preds = %32, %2
store i32 4, i32* %4
%18 = call i32 @recvfrom(i32 %9, i8* %8, i32 128, i32 0, %struct.sockaddr* %3, i32* %4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = sext i32 %18 to i64
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @narrate(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %8, %struct.sockaddr* %3)
%24 = call i32 @alarm(i32 0)
%25 = load i32, i32* %4
%26 = call i32 @handle_request(i8* %8, %struct.sockaddr* %3, i32 %25)
%27 = call i32 @alarm(i32 %24)
br label %32
28: ; preds = %17
%29 = load i64, i64* @errno
%30 = load i64, i64* @EINTR
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28, %33, %20
br label %17
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %32
}