#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*/ EXIT_FAILURE;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int init_sock(int type) {
  int fd;
  fd = socket(PF_INET, type, IPPROTO_TCP);
  if (fd < 0) {
    perror("Socket create error !");
    exit(EXIT_FAILURE);
  }
  printf("Socket Create OK\n");
  return fd;
}


x86 assembly (clang, -O0):
<init_sock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    118c <init_sock+0x4c>
lea    0xe87(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_sock>:
push   %rbx
mov    %edi,%esi
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
test   %eax,%eax
js     1170 <init_sock+0x30>
mov    %eax,%ebx
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe89(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@PF_INET = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [22 x i8] c"Socket create error !\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"Socket Create OK\0A\00"
define i32 @init_sock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* %2
%6 = load i32, i32* @IPPROTO_TCP
%7 = call i32 @socket(i32 %4, i32 %5, i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %3
ret i32 %16
}

LLVM IR (-O2):
@PF_INET = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [22 x i8] c"Socket create error !\00"
@EXIT_FAILURE = global i32 0
@str = [17 x i8] c"Socket Create OK\00"
define i32 @init_sock(i32 %0) {
%2 = load i32, i32* @PF_INET
%3 = load i32, i32* @IPPROTO_TCP
%4 = tail call i32 @socket(i32 %2, i32 %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
ret i32 %4
}