#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;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ logToSomeFile(char *, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int SendTo(char message[200], int port) {
  struct sockaddr_in serv_addr;
  int sockfd = 0;
  int clientsockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("Client: ERROR opening socket");
    exit(1);
  }
  memset(&serv_addr, '0', sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(port);
  logToSomeFile("Just testing this if it works", 2);
  if (inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr) <= 0) {
    logToSomeFile("Client inet_pton error occured", 3);
    return 1;
  }
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    logToSomeFile("Client Error : Connect Failed", 3);
    return 1;
  }
}


x86 assembly (clang, -O0):
<SendTo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11d2 <SendTo+0x52>
lea    0xe3d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0x30,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe1a(%rip),%rdi
mov    $0x2,%esi
call   1060 <logToSomeFile@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
lea    0xe1a(%rip),%rsi
call   1050 <inet_pton@plt>
cmp    $0x0,%rax
jg     124d <SendTo+0xcd>
lea    0xe0e(%rip),%rdi
mov    $0x3,%esi
call   1060 <logToSomeFile@plt>
movl   $0x1,-0x4(%rbp)
jmp    1280 <SendTo+0x100>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    1280 <SendTo+0x100>
lea    0xdf5(%rip),%rdi
mov    $0x3,%esi
call   1060 <logToSomeFile@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendTo>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    0x2e76(%rip),%r15
mov    (%r15),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x30,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe4d(%rip),%rdi
mov    $0x2,%esi
call   1060 <logToSomeFile@plt>
mov    (%r15),%edi
lea    0xe57(%rip),%rsi
mov    %r14,%rdx
call   1050 <inet_pton@plt>
test   %rax,%rax
jle    11f1 <SendTo+0x91>
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0xc,%edx
call   1070 <connect@plt>
test   %rax,%rax
jns    1202 <SendTo+0xa2>
lea    0xe58(%rip),%rdi
jmp    11f8 <SendTo+0x98>
lea    0xe30(%rip),%rdi
mov    $0x3,%esi
call   1060 <logToSomeFile@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [29 x i8] c"Client: ERROR opening socket\00"
@.str.1 = [30 x i8] c"Just testing this if it works\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [31 x i8] c"Client inet_pton error occured\00"
@.str.4 = [30 x i8] c"Client Error : Connect Failed\00"
define i32 @SendTo(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %7
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %8
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = call i32 @memset(%struct.sockaddr_in* %6, i32 48, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* %5
%22 = call i32 @htons(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @logToSomeFile(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 2)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%27 = call i64 @inet_pton(i32 %25, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %26)
%28 = icmp sle i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %17
%30 = call i32 @logToSomeFile(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 3)
store i32 1, i32* %3
br label %38
31: ; preds = %17
%32 = load i32, i32* %7
%33 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%34 = call i64 @connect(i32 %32, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @logToSomeFile(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 3)
store i32 1, i32* %3
br label %38
38: ; preds = %29, %36, %31
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [30 x i8] c"Just testing this if it works\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [31 x i8] c"Client inet_pton error occured\00"
@.str.4 = [30 x i8] c"Client Error : Connect Failed\00"
define i32 @SendTo(i8* nocapture readnone %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = call i32 @memset(%struct.sockaddr_in* %3, i32 48, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %9, i32* %10
%11 = call i32 @htons(i32 %1)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %11, i32* %12
%13 = call i32 @logToSomeFile(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 2)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%16 = call i64 @inet_pton(i32 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%17 = icmp slt i64 %16, 1
br i1 %17, label %22, label %18
18: ; preds = %2
%19 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%20 = call i64 @connect(i32 0, %struct.sockaddr* %19, i32 12)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18, %2
%23 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), %2 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), %18 ]
%24 = call i32 @logToSomeFile(i8* %23, i32 3)
br label %25
25: ; preds = %22, %18
ret i32 1
}