#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_storage {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ handle_request(int);
int /*<<< orphan*/ sh_print_client_ip(struct sockaddr_storage);
void server_main(int sockfd) {
  while (1) {
    struct sockaddr_storage client_addr;
    socklen_t addr_size;
    int clientfd;
    addr_size = sizeof client_addr;
    clientfd = accept(sockfd, (struct sockaddr *)&client_addr, &addr_size);
    sh_print_client_ip(client_addr);
    handle_request(clientfd);
    close(clientfd);
  }
}


x86 assembly (clang, -O0):
<server_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <sh_print_client_ip@plt>
mov    -0x10(%rbp),%edi
call   1050 <handle_request@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
jmp    114b <server_main+0xb>

x86 assembly (clang, -O2):
<server_main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%r14
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movl   $0x4,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <accept@plt>
mov    %eax,%ebp
mov    (%rsp),%edi
call   1030 <sh_print_client_ip@plt>
mov    %ebp,%edi
call   1050 <handle_request@plt>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    1160 <server_main+0x20>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
define void @server_main(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
br label %6
6: ; preds = %1, %6
store i32 4, i32* %4
%7 = load i32, i32* %2
%8 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%9 = call i32 @accept(i32 %7, %struct.sockaddr* %8, i32* %4)
store i32 %9, i32* %5
%10 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @sh_print_client_ip(i32 %11)
%13 = load i32, i32* %5
%14 = call i32 @handle_request(i32 %13)
%15 = load i32, i32* %5
%16 = call i32 @close(i32 %15)
br label %6
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
define void @server_main(i32 %0) {
%2 = alloca %struct.sockaddr_storage
%3 = alloca i32
%4 = bitcast %struct.sockaddr_storage* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sockaddr_storage* %2 to %struct.sockaddr*
%7 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 0, i32 0
br label %8
8: ; preds = %1, %8
store i32 4, i32* %3
%9 = call i32 @accept(i32 %0, %struct.sockaddr* %6, i32* %3)
%10 = load i32, i32* %7
%11 = call i32 @sh_print_client_ip(i32 %10)
%12 = call i32 @handle_request(i32 %9)
%13 = call i32 @close(i32 %9)
br label %8
}