#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;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ mkthread_serve(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
void accept_loop(int sockfd) {
  struct sockaddr_in addr;
  socklen_t sin_size = sizeof(struct sockaddr_in);
  while (1) {
    int spawned_sockfd = accept(sockfd, (struct sockaddr *)&addr, &sin_size);
    if (spawned_sockfd == -1) {
      perror("Error accept client");
      continue;
    }
    puts("received connection");
    mkthread_serve(spawned_sockfd);
  }
}


x86 assembly (clang, -O0):
<accept_loop>:
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)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1180 <accept_loop+0x40>
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
jmp    1152 <accept_loop+0x12>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%edi
call   1040 <mkthread_serve@plt>
jmp    1152 <accept_loop+0x12>

x86 assembly (clang, -O2):
<accept_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xe97(%rip),%r12
lea    0xea4(%rip),%r13
jmp    1191 <accept_loop+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ebp
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1040 <mkthread_serve@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <accept@plt>
cmp    $0xffffffff,%eax
jne    1180 <accept_loop+0x40>
mov    %r12,%rdi
call   1050 <perror@plt>
jmp    1191 <accept_loop+0x51>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"Error accept client\00"
@.str.1 = [20 x i8] c"received connection\00"
define void @accept_loop(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %4
br label %6
6: ; preds = %1, %12, %14
%7 = load i32, i32* %2
%8 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%9 = call i32 @accept(i32 %7, %struct.sockaddr* %8, i32* %4)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %6
14: ; preds = %6
%15 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %5
%17 = call i32 @mkthread_serve(i32 %16)
br label %6
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"Error accept client\00"
@.str.1 = [20 x i8] c"received connection\00"
define void @accept_loop(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %7
7: ; preds = %15, %1
%8 = call i32 @accept(i32 %0, %struct.sockaddr* %6, i32* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %15
12: ; preds = %7
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @mkthread_serve(i32 %8)
br label %15
15: ; preds = %12, %10
br label %7
}