#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int openTouchOscSocket() {
  int fd = socket(AF_INET, SOCK_DGRAM, 0);
  struct sockaddr_in sin;
  sin.sin_family = AF_INET;
  sin.sin_port = htons(2013);
  inet_aton("192.168.0.13", &sin.sin_addr);
  int err = connect(fd, (struct sockaddr *)&sin, sizeof(struct sockaddr_in));
  if (err != 0) {
    printf("Failed to open TouchOSC socket: %i\n", err);
    return -1;
  } else
    return fd;
}


x86 assembly (clang, -O0):
<openTouchOscSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x7dd,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1050 <inet_aton@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1060 <connect@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d6 <openTouchOscSocket+0x86>
mov    -0x1c(%rbp),%esi
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <openTouchOscSocket+0x8c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openTouchOscSocket>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e8a(%rip),%r14
mov    (%r14),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    $0x7dd,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0xe71(%rip),%rdi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1050 <inet_aton@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1060 <connect@plt>
test   %eax,%eax
je     11c2 <openTouchOscSocket+0x72>
lea    0xe57(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"192.168.0.13\00"
@.str.1 = [36 x i8] c"Failed to open TouchOSC socket: %i\0A\00"
define i32 @openTouchOscSocket() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %8, i32* %9
%10 = call i32 @htons(i32 2013)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%13 = call i32 @inet_aton(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %12)
%14 = load i32, i32* %2
%15 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%16 = call i32 @connect(i32 %14, %struct.sockaddr* %15, i32 12)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = load i32, i32* %4
%21 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 -1, i32* %1
br label %24
22: ; preds = %0
%23 = load i32, i32* %2
store i32 %23, i32* %1
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"192.168.0.13\00"
@.str.1 = [36 x i8] c"Failed to open TouchOSC socket: %i\0A\00"
define i32 @openTouchOscSocket() {
%1 = alloca %struct.sockaddr_in
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_DGRAM
%4 = tail call i32 @socket(i32 %2, i32 %3, i32 0)
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %6, i32* %7
%8 = tail call i32 @htons(i32 2013)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%11 = call i32 @inet_aton(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %10)
%12 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%13 = call i32 @connect(i32 %4, %struct.sockaddr* %12, i32 12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %17
17: ; preds = %0, %15
%18 = phi i32 [ -1, %15 ], [ %4, %0 ]
ret i32 %18
}