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

/* Variables and functions */
int /*<<< orphan*/ errno;
int ret_err(char **, char *, int /*<<< orphan*/);
int socket(int, int, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int etcp_socket(int family, int type, int protocol, char **errstr) {
  int s;
  if ((s = socket(family, type, protocol)) < 0)
    return ret_err(errstr, "socket: %s", strerror(errno));
  return s;
}


x86 assembly (clang, -O0):
<etcp_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    118f <etcp_socket+0x5f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe7e(%rip),%rsi
call   1030 <ret_err@plt>
mov    %eax,-0x4(%rbp)
jmp    1195 <etcp_socket+0x65>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<etcp_socket>:
push   %rbx
mov    %rcx,%rbx
call   1050 <socket@plt>
test   %eax,%eax
js     113f <etcp_socket+0xf>
pop    %rbx
ret
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
pop    %rbx
jmp    1030 <ret_err@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"socket: %s\00"
@errno = global i32 0
define i32 @etcp_socket(i32 %0, i32 %1, i32 %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8** %3, i8*** %9
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = call i32 @socket(i32 %11, i32 %12, i32 %13)
store i32 %14, i32* %10
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %4
%17 = load i8**, i8*** %9
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 @ret_err(i8** %17, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %5
br label %23
21: ; preds = %4
%22 = load i32, i32* %10
store i32 %22, i32* %5
br label %23
23: ; preds = %21, %16
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
@.str = [11 x i8] c"socket: %s\00"
@errno = global i32 0
define i32 @etcp_socket(i32 %0, i32 %1, i32 %2, i8** %3) {
%5 = tail call i32 @socket(i32 %0, i32 %1, i32 %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @ret_err(i8** %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %4, %7
%12 = phi i32 [ %10, %7 ], [ %5, %4 ]
ret i32 %12
}