#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 */
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int htxd_accept_connection(int socket_fd, struct sockaddr_in *p_client_address,
                           socklen_t *p_address_length) {
  int new_fd;
  memset((void *)p_client_address, 0, sizeof(struct sockaddr));
  *p_address_length = sizeof(struct sockaddr);
  new_fd =
      accept(socket_fd, (struct sockaddr *)p_client_address, p_address_length);
  if ((new_fd == -1) && (errno != EINTR)) {
    perror("ERROR: while accepting connection. Exiting...");
    exit(1);
  }
  return new_fd;
}


x86 assembly (clang, -O0):
<htxd_accept_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ba <htxd_accept_connection+0x7a>
mov    0x2e4f(%rip),%rax
mov    (%rax),%rax
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%rax
je     11ba <htxd_accept_connection+0x7a>
lea    0xe55(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htxd_accept_connection>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movl   $0x4,(%r14)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <accept@plt>
cmp    $0xffffffff,%eax
jne    118a <htxd_accept_connection+0x4a>
mov    0x2e65(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e53(%rip),%rdx
cmp    (%rdx),%rcx
jne    118f <htxd_accept_connection+0x4f>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe6a(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [46 x i8] c"ERROR: while accepting connection. Exiting...\00"
define i32 @htxd_accept_connection(i32 %0, %struct.sockaddr_in* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
store i32* %2, i32** %6
%8 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%9 = bitcast %struct.sockaddr_in* %8 to i8*
%10 = call i32 @memset(i8* %9, i32 0, i32 4)
%11 = load i32*, i32** %6
store i32 4, i32* %11
%12 = load i32, i32* %4
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%14 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%15 = load i32*, i32** %6
%16 = call i32 @accept(i32 %12, %struct.sockaddr* %14, i32* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %3
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19, %3
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [46 x i8] c"ERROR: while accepting connection. Exiting...\00"
define i32 @htxd_accept_connection(i32 %0, %struct.sockaddr_in* %1, i32* %2) {
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = tail call i32 @memset(i8* %4, i32 0, i32 4)
store i32 4, i32* %2
%6 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%7 = tail call i32 @accept(i32 %0, %struct.sockaddr* %6, i32* %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9, %3
ret i32 %7
}