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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void print(char *ip, int port) {
  int s;
  struct sockaddr_in sv;
  char m[8192];
  s = socket(AF_INET, SOCK_STREAM, 0);
  if (s == -1) {
    printf("No socket :(\n");
    return;
  }
  sv.sin_addr.s_addr = inet_addr(ip);
  sv.sin_family = AF_INET;
  sv.sin_port = htons(port);
  if (connect(s, (struct sockaddr *)&sv, sizeof(sv)) < 0) {
    perror("No communication :(\n");
    return;
  }
  if (recv(s, m, sizeof(m), 0) < 0) {
    puts("No data :(");
    return;
  }
  printf(m);
  close(s);
  return;
}


x86 assembly (clang, -O0):
<print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11d9 <print+0x49>
lea    0xe31(%rip),%rdi
call   1060 <printf@plt>
jmp    126d <print+0xdd>
mov    -0x8(%rbp),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1228 <print+0x98>
lea    0xdf0(%rip),%rdi
call   1090 <perror@plt>
jmp    126d <print+0xdd>
mov    -0x10(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jge    1259 <print+0xc9>
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
jmp    126d <print+0xdd>
lea    -0x2020(%rbp),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2018,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2e3e(%rip),%r15
mov    (%r15),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1221 <print+0x91>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    (%r15),%eax
mov    %eax,0x4(%rsp)
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     1254 <print+0xc4>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     123a <print+0xaa>
lea    0x10(%rsp),%rdi
call   1060 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
jmp    1246 <print+0xb6>
lea    0xdf8(%rip),%rdi
add    $0x2018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
add    $0x2018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda5(%rip),%rdi
call   1090 <perror@plt>
jmp    1246 <print+0xb6>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"No socket :(\0A\00"
@.str.1 = [21 x i8] c"No communication :(\0A\00"
@.str.2 = [11 x i8] c"No data :(\00"
define void @print(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca [8192 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %43
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 @inet_addr(i8* %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* %4
%23 = call i32 @htons(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %5
%26 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%27 = call i64 @connect(i32 %25, %struct.sockaddr* %26, i32 12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %15
%30 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %43
31: ; preds = %15
%32 = load i32, i32* %5
%33 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%34 = call i64 @recv(i32 %32, i8* %33, i32 8192, i32 0)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %43
38: ; preds = %31
%39 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%40 = call i32 @printf(i8* %39)
%41 = load i32, i32* %5
%42 = call i32 @close(i32 %41)
br label %43
43: ; preds = %38, %36, %29, %13
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"No communication :(\0A\00"
@.str.2 = [11 x i8] c"No data :(\00"
@str = [13 x i8] c"No socket :(\00"
define void @print(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [8192 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %33
13: ; preds = %2
%14 = tail call i32 @inet_addr(i8* %0)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 %1)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i64 @connect(i32 %9, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %33
25: ; preds = %13
%26 = call i64 @recv(i32 %9, i8* %6, i32 8192, i32 0)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %33
30: ; preds = %25
%31 = call i32 @printf(i8* %6)
%32 = call i32 @close(i32 %9)
br label %33
33: ; preds = %30, %28, %23, %11
ret void
}