#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 */
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*/ peer_addr;
typedef int /*<<< orphan*/ broadcast;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int make_udp_socket() {
  int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
  if (sockfd > 0) {
    int broadcast = 1;
    if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &broadcast,
                   sizeof(broadcast)) == 0) {
      struct sockaddr_in peer_addr;
      peer_addr.sin_family = AF_INET;
      peer_addr.sin_port = htons(21453);
      peer_addr.sin_addr.s_addr = inet_addr("127.0.0.255");
      bind(sockfd, (struct sockaddr *)&peer_addr, sizeof(peer_addr));
      if (connect(sockfd, (struct sockaddr *)&peer_addr, sizeof(peer_addr)) ==
          0) {
      } else {
        close(sockfd);
        sockfd = -1;
      }
    } else {
      close(sockfd);
      sockfd = -1;
    }
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<make_udp_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1254 <make_udp_socket+0xe4>
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jne    1240 <make_udp_socket+0xd0>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x53cd,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xe0d(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
cmp    $0x0,%rax
jne    122c <make_udp_socket+0xbc>
jmp    123b <make_udp_socket+0xcb>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <make_udp_socket+0xdf>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <make_udp_socket+0xe4>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_udp_socket>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    122a <make_udp_socket+0xba>
movl   $0x1,0x4(%rsp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jne    121e <make_udp_socket+0xae>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x53cd,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0xe13(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
test   %rax,%rax
je     122a <make_udp_socket+0xba>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@AF_INET = global i32 0
@.str = [12 x i8] c"127.0.0.255\00"
define i32 @make_udp_socket() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %39
9: ; preds = %0
store i32 1, i32* %2
%10 = load i32, i32* %1
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_BROADCAST
%13 = call i64 @setsockopt(i32 %10, i32 %11, i32 %12, i32* %2, i32 4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %35
15: ; preds = %9
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %16, i32* %17
%18 = call i32 @htons(i32 21453)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %1
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @bind(i32 %23, %struct.sockaddr* %24, i32 12)
%26 = load i32, i32* %1
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i64 @connect(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %15
br label %34
31: ; preds = %15
%32 = load i32, i32* %1
%33 = call i32 @close(i32 %32)
store i32 -1, i32* %1
br label %34
34: ; preds = %31, %30
br label %38
35: ; preds = %9
%36 = load i32, i32* %1
%37 = call i32 @close(i32 %36)
store i32 -1, i32* %1
br label %38
38: ; preds = %35, %34
br label %39
39: ; preds = %38, %0
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@AF_INET = global i32 0
@.str = [12 x i8] c"127.0.0.255\00"
define i32 @make_udp_socket() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %33
7: ; preds = %0
%8 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%9 = load i32, i32* @SOL_SOCKET
%10 = load i32, i32* @SO_BROADCAST
%11 = call i64 @setsockopt(i32 %5, i32 %9, i32 %10, i32* %1, i32 4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %7
%14 = bitcast %struct.sockaddr_in* %2 to i8*
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @htons(i32 21453)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %17, i32* %18
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%22 = call i32 @bind(i32 %5, %struct.sockaddr* %21, i32 12)
%23 = call i64 @connect(i32 %5, %struct.sockaddr* %21, i32 12)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %13
%26 = call i32 @close(i32 %5)
br label %27
27: ; preds = %13, %25
%28 = phi i32 [ %5, %13 ], [ -1, %25 ]
br label %31
29: ; preds = %7
%30 = call i32 @close(i32 %5)
br label %31
31: ; preds = %29, %27
%32 = phi i32 [ %28, %27 ], [ -1, %29 ]
br label %33
33: ; preds = %31, %0
%34 = phi i32 [ %32, %31 ], [ %5, %0 ]
ret i32 %34
}