#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__ {
  unsigned int s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_SNDBUF;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(unsigned int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int udpclient(unsigned int serverip, unsigned int targetport) {
  int conn_s;
  struct sockaddr_in servaddr;
  int sndsize = 1024 * 1024, ret = 0;
  if ((conn_s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    fprintf(stderr, "Error creating socket.\n");
    return -1;
  }
  ret =
      setsockopt(conn_s, SOL_SOCKET, SO_SNDBUF, (char *)&sndsize, sizeof(int));
  sndsize = 1024 * 1024;
  ret =
      setsockopt(conn_s, SOL_SOCKET, SO_RCVBUF, (char *)&sndsize, sizeof(int));
  return conn_s;
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(targetport);
  servaddr.sin_addr.s_addr = serverip;
  if (connect(conn_s, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    printf("Error calling connect()\n");
    return -1;
  }
  return conn_s;
}


x86 assembly (clang, -O0):
<udpclient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x100000,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    1192 <udpclient+0x62>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <udpclient+0xbd>
mov    -0x10(%rbp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x28(%rbp)
movl   $0x100000,-0x24(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
mov    0x2ded(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udpclient>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x100000,0xc(%rsp)
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
test   %eax,%eax
js     11ae <udpclient+0x7e>
mov    %eax,%ebx
mov    0x2e81(%rip),%r15
mov    (%r15),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movl   $0x100000,0xc(%rsp)
mov    (%r15),%esi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
jmp    11c8 <udpclient+0x98>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Error creating socket.\0A\00"
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@SO_RCVBUF = global i32 0
define i32 @udpclient(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 1048576, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
17: ; preds = %2
%18 = load i32, i32* %6
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_SNDBUF
%21 = bitcast i32* %8 to i8*
%22 = call i32 @setsockopt(i32 %18, i32 %19, i32 %20, i8* %21, i32 4)
store i32 %22, i32* %9
store i32 1048576, i32* %8
%23 = load i32, i32* %6
%24 = load i32, i32* @SOL_SOCKET
%25 = load i32, i32* @SO_RCVBUF
%26 = bitcast i32* %8 to i8*
%27 = call i32 @setsockopt(i32 %23, i32 %24, i32 %25, i8* %26, i32 4)
store i32 %27, i32* %9
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %17, %14
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Error creating socket.\0A\00"
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@SO_RCVBUF = global i32 0
define i32 @udpclient(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 1048576, i32* %3
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %19
12: ; preds = %2
%13 = load i32, i32* @SOL_SOCKET
%14 = load i32, i32* @SO_SNDBUF
%15 = call i32 @setsockopt(i32 %7, i32 %13, i32 %14, i8* %4, i32 4)
store i32 1048576, i32* %3
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_RCVBUF
%18 = call i32 @setsockopt(i32 %7, i32 %16, i32 %17, i8* %4, i32 4)
br label %19
19: ; preds = %12, %9
%20 = phi i32 [ -1, %9 ], [ %7, %12 ]
ret i32 %20
}