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

/* Variables and functions */
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int accept_waiting_connection(int server, struct sockaddr *connection,
                              socklen_t *len) {
  int c_fd;
  if ((c_fd = accept(server, connection, len)) == -1) {
    perror("accept_waiting_connection: accept");
    exit(1);
  } else {
    printf("connected");
  }
  return c_fd;
}


x86 assembly (clang, -O0):
<accept_waiting_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1185 <accept_waiting_connection+0x45>
lea    0xe8a(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_waiting_connection>:
push   %rbx
call   1050 <accept@plt>
cmp    $0xffffffff,%eax
je     115d <accept_waiting_connection+0x1d>
mov    %eax,%ebx
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe9c(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [34 x i8] c"accept_waiting_connection: accept\00"
@.str.1 = [10 x i8] c"connected\00"
define i32 @accept_waiting_connection(i32 %0, %struct.sockaddr* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32* %2, i32** %6
%8 = load i32, i32* %4
%9 = load %struct.sockaddr*, %struct.sockaddr** %5
%10 = load i32*, i32** %6
%11 = call i32 @accept(i32 %8, %struct.sockaddr* %9, i32* %10)
store i32 %11, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16
%19 = load i32, i32* %7
ret i32 %19
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [34 x i8] c"accept_waiting_connection: accept\00"
@.str.1 = [10 x i8] c"connected\00"
define i32 @accept_waiting_connection(i32 %0, %struct.sockaddr* %1, i32* %2) {
%4 = tail call i32 @accept(i32 %0, %struct.sockaddr* %1, i32* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %3
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
ret i32 %4
}