#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 in_addr {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  struct in_addr sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
void *htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int intSockFD, intNumBytes;
  char chaBuffer[100];
  struct hostent *strHostEntity;
  struct sockaddr_in strSockRemote, strSockLocal;
  if (argc != 2) {
    fprintf(stderr, "Errrr... the usage is: \"%s <hostname>\n", argv[0]);
    exit(1);
  }
  if ((strHostEntity = gethostbyname(argv[1])) == NULL) {
    fprintf(
        stderr,
        "Failed converting hostname... too lazy to give you the errno :P\n");
    exit(1);
  }
  strSockLocal.sin_family = AF_INET;
  strSockLocal.sin_port = htons(9999);
  inet_aton("10.0.0.7", &strSockLocal.sin_addr.s_addr);
  if ((intSockFD = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
    perror("Failed creating socket because... :");
    exit(1);
  }
  if (bind(intSockFD, (struct sockaddr *)&strSockLocal, sizeof strSockLocal) ==
      -1) {
    perror("Failed binding socket because... :");
    exit(1);
  }
  strSockRemote.sin_family = AF_INET;
  strSockRemote.sin_port = htons(25);
  strSockRemote.sin_addr = *((struct in_addr *)strHostEntity->h_addr);
  memset(strSockRemote.sin_zero, '\0', sizeof strSockRemote.sin_zero);
  if (connect(intSockFD, (struct sockaddr *)&strSockRemote,
              sizeof strSockRemote) == -1) {
    perror("Failed connecting socket because... :");
    exit(1);
  }
  if ((intNumBytes = recv(intSockFD, chaBuffer, 100 - 1, 0)) == -1) {
    perror("Failed receiving socket data because... :");
    exit(1);
  }
  chaBuffer[intNumBytes] = '\0';
  printf("From remote side :: %s", chaBuffer);
  close(intSockFD);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     121b <main+0x4b>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    125a <main+0x8a>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    $0x270f,%edi
call   1040 <htons@plt>
mov    %rax,-0xb0(%rbp)
lea    -0xb8(%rbp),%rsi
add    $0x4,%rsi
lea    0xdda(%rip),%rdi
call   10a0 <inet_aton@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12ce <main+0xfe>
lea    0xdb2(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0xb8(%rbp),%rsi
mov    $0x18,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1301 <main+0x131>
lea    0xda3(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x90(%rbp)
mov    $0x19,%edi
call   1040 <htons@plt>
mov    %rax,-0x98(%rbp)
mov    -0x88(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0xa0(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x18,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    137a <main+0x1aa>
lea    0xd4d(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    13af <main+0x1df>
lea    0xd3e(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xd45(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
cmp    $0x2,%edi
jne    12f5 <main+0x125>
mov    0x8(%rsi),%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     1319 <main+0x149>
mov    %rax,%r14
mov    0x2de7(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    $0x270f,%edi
call   1040 <htons@plt>
mov    %rax,0x8(%rsp)
lea    0x4(%rsp),%rsi
lea    0xe44(%rip),%rdi
call   10a0 <inet_aton@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     133a <main+0x16a>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     1343 <main+0x173>
mov    (%r15),%rax
mov    %rax,0x28(%rsp)
mov    $0x19,%edi
call   1040 <htons@plt>
mov    %rax,0x20(%rsp)
mov    (%r14),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
mov    $0x18,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     134c <main+0x17c>
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     1355 <main+0x185>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xe33(%rip),%rdi
lea    0x30(%rsp),%rsi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xcf8(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
lea    0xcfe(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd30(%rip),%rdi
jmp    135c <main+0x18c>
lea    0xd4b(%rip),%rdi
jmp    135c <main+0x18c>
lea    0xd65(%rip),%rdi
jmp    135c <main+0x18c>
lea    0xd82(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32, %struct.in_addr, i8*, i8* }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Errrr... the usage is: \22%s <hostname>\0A\00"
@.str.1 = [65 x i8] c"Failed converting hostname... too lazy to give you the errno :P\0A\00"
@AF_INET = global i8* null
@.str.2 = [9 x i8] c"10.0.0.7\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [36 x i8] c"Failed creating socket because... :\00"
@.str.4 = [35 x i8] c"Failed binding socket because... :\00"
@.str.5 = [38 x i8] c"Failed connecting socket because... :\00"
@.str.6 = [42 x i8] c"Failed receiving socket data because... :\00"
@.str.7 = [23 x i8] c"From remote side :: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca %struct.hostent*
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call %struct.hostent* @gethostbyname(i8* %24)
store %struct.hostent* %25, %struct.hostent** %9
%26 = icmp eq %struct.hostent* %25, null
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = load i8*, i8** @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 3
store i8* %32, i8** %33
%34 = call i8* @htons(i32 9999)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i8* %34, i8** %35
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%37 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %36, i32 0, i32 0
%38 = call i32 @inet_aton(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %37)
%39 = load i32, i32* @PF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %6
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %31
%44 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %31
%47 = load i32, i32* %6
%48 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%49 = call i32 @bind(i32 %47, %struct.sockaddr* %48, i32 24)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %46
%55 = load i8*, i8** @AF_INET
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i8* %55, i8** %56
%57 = call i8* @htons(i32 25)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i8* %57, i8** %58
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%60 = load %struct.hostent*, %struct.hostent** %9
%61 = getelementptr inbounds %struct.hostent, %struct.hostent* %60, i32 0, i32 0
%62 = load i64, i64* %61
%63 = inttoptr i64 %62 to %struct.in_addr*
%64 = bitcast %struct.in_addr* %59 to i8*
%65 = bitcast %struct.in_addr* %63 to i8*
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i32 @memset(i32 %67, i8 signext 0, i32 4)
%69 = load i32, i32* %6
%70 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%71 = call i32 @connect(i32 %69, %struct.sockaddr* %70, i32 24)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %54
%74 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %54
%77 = load i32, i32* %6
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%79 = call i32 @recv(i32 %77, i8* %78, i32 99, i32 0)
store i32 %79, i32* %7
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %84
81: ; preds = %76
%82 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %76
%85 = load i32, i32* %7
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %86
store i8 0, i8* %87
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%89 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %88)
%90 = load i32, i32* %6
%91 = call i32 @close(i32 %90)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i8*, i8* }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Errrr... the usage is: \22%s <hostname>\0A\00"
@.str.1 = [65 x i8] c"Failed converting hostname... too lazy to give you the errno :P\0A\00"
@AF_INET = global i8* null
@.str.2 = [9 x i8] c"10.0.0.7\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [36 x i8] c"Failed creating socket because... :\00"
@.str.4 = [35 x i8] c"Failed binding socket because... :\00"
@.str.5 = [38 x i8] c"Failed connecting socket because... :\00"
@.str.6 = [42 x i8] c"Failed receiving socket data because... :\00"
@.str.7 = [23 x i8] c"From remote side :: %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call %struct.hostent* @gethostbyname(i8* %17)
%19 = icmp eq %struct.hostent* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = load i8*, i8** @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 3
store i8* %25, i8** %26
%27 = tail call i8* @htons(i32 9999)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i8* %27, i8** %28
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
%30 = call i32 @inet_aton(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %29)
%31 = load i32, i32* @PF_INET
%32 = load i32, i32* @SOCK_STREAM
%33 = call i32 @socket(i32 %31, i32 %32, i32 0)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %24
%36 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %24
%39 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%40 = call i32 @bind(i32 %33, %struct.sockaddr* %39, i32 24)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %38
%46 = load i8*, i8** @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i8* %46, i8** %47
%48 = call i8* @htons(i32 25)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %48, i8** %49
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i64 0, i32 0
%51 = load i64, i64* %50
%52 = inttoptr i64 %51 to i32*
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%54 = load i32, i32* %52
store i32 %54, i32* %53
%55 = call i32 @memset(i32 undef, i8 signext 0, i32 4)
%56 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%57 = call i32 @connect(i32 %33, %struct.sockaddr* %56, i32 24)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %45
%60 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %45
%63 = call i32 @recv(i32 %33, i8* %6, i32 99, i32 0)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %62
%69 = sext i32 %63 to i64
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %69
store i8 0, i8* %70
%71 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %6)
%72 = call i32 @close(i32 %33)
ret i32 0
}