#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 */
scalar_t__ ENOSYS;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ abort();
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(void) {
  int ret = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (ret != -1) {
    fprintf(stderr, "sock: %d\n", ret);
    abort();
  }
  if (errno != ENOSYS) {
    perror("unexpected");
    abort();
  }
  printf("pass\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     11ab <main+0x5b>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%rax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
je     11d8 <main+0x88>
lea    0xe3e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
jne    119c <main+0x4c>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
jne    11ba <main+0x6a>
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%edi
lea    0xe54(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xe49(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [10 x i8] c"sock: %d\0A\00"
@errno = global i64 0
@ENOSYS = global i64 0
@.str.1 = [11 x i8] c"unexpected\00"
@.str.2 = [6 x i8] c"pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = load i32, i32* @IPPROTO_TCP
%6 = call i32 @socket(i32 %3, i32 %4, i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* %2
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %0
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOSYS
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %14
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [10 x i8] c"sock: %d\0A\00"
@errno = global i64 0
@ENOSYS = global i64 0
@.str.1 = [11 x i8] c"unexpected\00"
@str = [5 x i8] c"pass\00"
define i32 @main() {
%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 %10, label %6
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %0
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOSYS
%13 = icmp eq i64 %11, %12
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 (...) @abort()
unreachable
17: ; preds = %10
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret i32 0
}