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

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ process_request(int, char const *);
int process_connection(int sockfd, const char *path) {
  int newsockfd;
  struct sockaddr cli_addr;
  socklen_t cli_addr_len;
  cli_addr_len = sizeof(cli_addr);
  newsockfd = accept(sockfd, &cli_addr, &cli_addr_len);
  if (newsockfd < 0)
    goto error;
  if (process_request(newsockfd, path) != 0)
    goto error;
  close(newsockfd);
  return 0;
error:
  close(newsockfd);
  perror("ERROR processing the connection");
  return 1;
}


x86 assembly (clang, -O0):
<process_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1178 <process_connection+0x38>
jmp    11a7 <process_connection+0x67>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <process_request@plt>
cmp    $0x0,%rax
je     1193 <process_connection+0x53>
jmp    11a7 <process_connection+0x67>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <process_connection+0x82>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
lea    0xe4a(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_connection>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1060 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1187 <process_connection+0x47>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <process_request@plt>
test   %rax,%rax
jne    1187 <process_connection+0x47>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    %ebx,%edi
call   1040 <close@plt>
lea    0xe6b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
jmp    117f <process_connection+0x3f>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [32 x i8] c"ERROR processing the connection\00"
define i32 @process_connection(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 4, i32* %8
%9 = load i32, i32* %4
%10 = call i32 @accept(i32 %9, %struct.sockaddr* %7, i32* %8)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %23
14: ; preds = %2
%15 = load i32, i32* %6
%16 = load i8*, i8** %5
%17 = call i64 @process_request(i32 %15, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
br label %23
20: ; preds = %14
%21 = load i32, i32* %6
%22 = call i32 @close(i32 %21)
store i32 0, i32* %3
br label %27
23: ; preds = %19, %13
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
%26 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %27
27: ; preds = %23, %20
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [32 x i8] c"ERROR processing the connection\00"
define i32 @process_connection(i32 %0, i8* %1) {
%3 = alloca %struct.sockaddr
%4 = alloca i32
%5 = bitcast %struct.sockaddr* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%7 = call i32 @accept(i32 %0, %struct.sockaddr* %3, i32* %4)
%8 = icmp slt i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = call i64 @process_request(i32 %7, i8* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @close(i32 %7)
br label %17
14: ; preds = %9, %2
%15 = call i32 @close(i32 %7)
%16 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %12
%18 = phi i32 [ 1, %14 ], [ 0, %12 ]
ret i32 %18
}