#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*/ close(int);
scalar_t__ socket_join_multicast(int, char *);
int socket_open(char *, int);
scalar_t__ socket_set_nonblock(int);
int input_init_udp(char *ip, int port) {
  int sock;
  sock = socket_open(ip, port);
  if (sock < 0)
    return sock;
  if (socket_set_nonblock(sock) < 0) {
    close(sock);
    return -1;
  }
  if (socket_join_multicast(sock, ip) < 0) {
    close(sock);
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<input_init_udp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <socket_open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1173 <input_init_udp+0x33>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c9 <input_init_udp+0x89>
mov    -0x18(%rbp),%edi
call   1030 <socket_set_nonblock@plt>
cmp    $0x0,%rax
jge    1199 <input_init_udp+0x59>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <input_init_udp+0x89>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <socket_join_multicast@plt>
cmp    $0x0,%rax
jge    11c3 <input_init_udp+0x83>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <input_init_udp+0x89>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input_init_udp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <socket_open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1179 <input_init_udp+0x39>
mov    %ebx,%edi
call   1030 <socket_set_nonblock@plt>
test   %rax,%rax
js     116d <input_init_udp+0x2d>
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <socket_join_multicast@plt>
test   %rax,%rax
jns    1179 <input_init_udp+0x39>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @input_init_udp(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = call i32 @socket_open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* %6
store i32 %13, i32* %3
br label %31
14: ; preds = %2
%15 = load i32, i32* %6
%16 = call i64 @socket_set_nonblock(i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %6
%20 = call i32 @close(i32 %19)
store i32 -1, i32* %3
br label %31
21: ; preds = %14
%22 = load i32, i32* %6
%23 = load i8*, i8** %4
%24 = call i64 @socket_join_multicast(i32 %22, i8* %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
store i32 -1, i32* %3
br label %31
29: ; preds = %21
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %31
31: ; preds = %29, %26, %18, %12
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @input_init_udp(i8* %0, i32 %1) {
%3 = tail call i32 @socket_open(i8* %0, i32 %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i64 @socket_set_nonblock(i32 %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i64 @socket_join_multicast(i32 %3, i8* %0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %5
%12 = tail call i32 @close(i32 %3)
br label %13
13: ; preds = %11, %8, %2
%14 = phi i32 [ %3, %2 ], [ %3, %8 ], [ -1, %11 ]
ret i32 %14
}