#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int uint16_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int SOCK_DGRAM;
int SOCK_STREAM;
int /*<<< orphan*/ assert(int);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, ...);
int /*<<< orphan*/ getsockname(int, struct sockaddr *, unsigned int *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ msg(char *, int);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int make_socket_inet(int typeP, uint16_t *portP,
                     struct sockaddr_in *ptr_addressP) {
  int sock;
  unsigned int length = sizeof(struct sockaddr_in);
  struct sockaddr_in name;
  assert((typeP == SOCK_STREAM) || (typeP == SOCK_DGRAM));
  sock = socket(PF_INET, typeP, 0);
  if (sock < 0) {
    fprintf(stderr, "ERROR: %s line %d socket %m",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/herlesupreeth/OAI-5G/refs/heads/emage/"
            "openair1/SIMULATION/ETH_TRANSPORT/socket.c",
            96);
    exit(EXIT_FAILURE);
  }
  name.sin_family = AF_INET;
  name.sin_port = htons(*portP);
  name.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(sock, (struct sockaddr *)&name, sizeof(name)) < 0) {
    close(sock);
    fprintf(stderr, "ERROR: %s line %d bind port %d %m",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/herlesupreeth/OAI-5G/refs/heads/emage/"
            "openair1/SIMULATION/ETH_TRANSPORT/socket.c",
            107, *portP);
    exit(EXIT_FAILURE);
  }
  if (ptr_addressP != NULL) {
    getsockname(sock, (struct sockaddr *)ptr_addressP, &length);
  }
  msg("[SOCKET] bound socket port %d\n", *portP);
  return sock;
}


x86 assembly (clang, -O0):
<make_socket_inet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xc,-0x20(%rbp)
mov    -0x4(%rbp),%ecx
mov    $0x1,%al
mov    0x2dfa(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x31(%rbp)
je     11e3 <make_socket_inet+0x43>
mov    -0x4(%rbp),%eax
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1241 <make_socket_inet+0xa1>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
lea    0xdf5(%rip),%rdx
mov    $0x60,%ecx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    12c7 <make_socket_inet+0x127>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%r8d
lea    0xe21(%rip),%rsi
lea    0xd6f(%rip),%rdx
mov    $0x6b,%ecx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
je     12e2 <make_socket_inet+0x142>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1090 <getsockname@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xdfa(%rip),%rdi
call   10b0 <msg@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_socket_inet>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e09(%rip),%rax
cmp    %edi,(%rax)
sete   %al
mov    0x2e15(%rip),%rcx
cmp    %edi,(%rcx)
movl   $0xc,0xc(%rsp)
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1060 <assert@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     125f <make_socket_inet+0xbf>
mov    %eax,%ebp
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    (%rbx),%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
js     1284 <make_socket_inet+0xe4>
test   %r14,%r14
je     1246 <make_socket_inet+0xa6>
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   1090 <getsockname@plt>
mov    (%rbx),%esi
lea    0xe9a(%rip),%rdi
call   10b0 <msg@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
lea    0xda6(%rip),%rdx
mov    $0x60,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12b1 <make_socket_inet+0x111>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%r8d
lea    0xe29(%rip),%rsi
lea    0xd77(%rip),%rdx
mov    $0x6b,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SOCK_STREAM = global i32 0
@SOCK_DGRAM = global i32 0
@PF_INET = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"ERROR: %s line %d socket %m\00"
@.str.1 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/herlesupreeth/OAI-5G/refs/heads/emage/openair1/SIMULATION/ETH_TRANSPORT/socket.c\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [34 x i8] c"ERROR: %s line %d bind port %d %m\00"
@.str.3 = [31 x i8] c"[SOCKET] bound socket port %d\0A\00"
define i32 @make_socket_inet(i32 %0, i32* %1, %struct.sockaddr_in* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.sockaddr_in*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
store i32 %0, i32* %4
store i32* %1, i32** %5
store %struct.sockaddr_in* %2, %struct.sockaddr_in** %6
store i32 12, i32* %8
%10 = load i32, i32* %4
%11 = load i32, i32* @SOCK_STREAM
%12 = icmp eq i32 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %3
%14 = load i32, i32* %4
%15 = load i32, i32* @SOCK_DGRAM
%16 = icmp eq i32 %14, %15
br label %17
17: ; preds = %13, %3
%18 = phi i1 [ true, %3 ], [ %16, %13 ]
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* @PF_INET
%22 = load i32, i32* %4
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 96)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %17
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i32*, i32** %5
%35 = load i32, i32* %34
%36 = call i32 @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %36, i32* %37
%38 = load i32, i32* @INADDR_ANY
%39 = call i32 @htonl(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
store i32 %39, i32* %41
%42 = load i32, i32* %7
%43 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%44 = call i64 @bind(i32 %42, %struct.sockaddr* %43, i32 12)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %31
%47 = load i32, i32* %7
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* @stderr
%50 = load i32*, i32** %5
%51 = load i32, i32* %50
%52 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 107, i32 %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %31
%56 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%57 = icmp ne %struct.sockaddr_in* %56, null
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i32, i32* %7
%60 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%61 = bitcast %struct.sockaddr_in* %60 to %struct.sockaddr*
%62 = call i32 @getsockname(i32 %59, %struct.sockaddr* %61, i32* %8)
br label %63
63: ; preds = %58, %55
%64 = load i32*, i32** %5
%65 = load i32, i32* %64
%66 = call i32 @msg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %7
ret i32 %67
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SOCK_STREAM = global i32 0
@SOCK_DGRAM = global i32 0
@PF_INET = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"ERROR: %s line %d socket %m\00"
@.str.1 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/herlesupreeth/OAI-5G/refs/heads/emage/openair1/SIMULATION/ETH_TRANSPORT/socket.c\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [34 x i8] c"ERROR: %s line %d bind port %d %m\00"
@.str.3 = [31 x i8] c"[SOCKET] bound socket port %d\0A\00"
define i32 @make_socket_inet(i32 %0, i32* nocapture %1, %struct.sockaddr_in* %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = bitcast i32* %4 to i8*
store i32 12, i32* %4
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = load i32, i32* @SOCK_STREAM
%9 = icmp eq i32 %8, %0
%10 = load i32, i32* @SOCK_DGRAM
%11 = icmp eq i32 %10, %0
%12 = select i1 %9, i1 true, i1 %11
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = load i32, i32* @PF_INET
%16 = tail call i32 @socket(i32 %15, i32 %0, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 96)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %3
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* %1
%27 = tail call i32 @htons(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = tail call i32 @htonl(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %30, i32* %31
%32 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%33 = call i64 @bind(i32 %16, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %23
%36 = call i32 @close(i32 %16)
%37 = load i32, i32* @stderr
%38 = load i32, i32* %1
%39 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.1, i64 0, i64 0), i32 107, i32 %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %23
%43 = icmp eq %struct.sockaddr_in* %2, null
br i1 %43, label %47, label %44
44: ; preds = %42
%45 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%46 = call i32 @getsockname(i32 %16, %struct.sockaddr* %45, i32* %4)
br label %47
47: ; preds = %44, %42
%48 = load i32, i32* %1
%49 = call i32 @msg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %48)
ret i32 %16
}