#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 /*<<< orphan*/ EXIT_FAILURE;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int safe_accept(int socket, struct sockaddr_in *address) {
  socklen_t address_len = sizeof(*address);
  int rvalue = accept(socket, (struct sockaddr *)address, &address_len);
  if (rvalue == -1) {
    perror("safe_accept - Failed to create socket");
    exit(EXIT_FAILURE);
  }
  return rvalue;
}


x86 assembly (clang, -O0):
<safe_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    117d <safe_accept+0x4d>
lea    0xe96(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_accept>:
push   %rax
movl   $0x4,0x4(%rsp)
lea    0x4(%rsp),%rdx
call   1040 <accept@plt>
cmp    $0xffffffff,%eax
je     114a <safe_accept+0x1a>
pop    %rcx
ret
lea    0xeaf(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [38 x i8] c"safe_accept - Failed to create socket\00"
@EXIT_FAILURE = global i32 0
define i32 @safe_accept(i32 %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%5 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%6 = call i32 @accept(i32 %0, %struct.sockaddr* %5, i32* %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
ret i32 %6
}