#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*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int some_doing_socket(void) {
  int sock;
  sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock == -1) {
    (void)fprintf(stderr, "socket failed: %s\n", strerror(errno));
    exit(1);
  }
  return (sock);
}


x86 assembly (clang, -O0):
<some_doing_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11ab <some_doing_socket+0x6b>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x8(%rbp),%edi
mov    %rax,%rdx
lea    0xe64(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<some_doing_socket>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
cmp    $0xffffffff,%eax
je     1168 <some_doing_socket+0x28>
pop    %rbx
ret
mov    0x2e69(%rip),%rax
mov    (%rax),%ebx
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"socket failed: %s\0A\00"
@errno = global i32 0
define i32 @some_doing_socket() {
%1 = alloca i32
%2 = load i32, i32* @PF_INET
%3 = load i32, i32* @SOCK_STREAM
%4 = load i32, i32* @IPPROTO_TCP
%5 = call i32 @socket(i32 %2, i32 %3, i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"socket failed: %s\0A\00"
@errno = global i32 0
define i32 @some_doing_socket() {
%1 = load i32, i32* @PF_INET
%2 = load i32, i32* @SOCK_STREAM
%3 = load i32, i32* @IPPROTO_TCP
%4 = tail call i32 @socket(i32 %1, i32 %2, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
ret i32 %4
}