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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  struct sockaddr_in server_info;
  struct hostent *he;
  int socket_fd, num;
  char buffer[1024];
  char buff[1024];
  if (argc != 2) {
    fprintf(stderr, "Usage: client hostname\n");
    exit(1);
  }
  if ((he = gethostbyname(argv[1])) == NULL) {
    fprintf(stderr, "Cannot get host name\n");
    exit(1);
  }
  if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    fprintf(stderr, "Socket Failure!!\n");
    exit(1);
  }
  memset(&server_info, 0, sizeof(server_info));
  server_info.sin_family = AF_INET;
  server_info.sin_port = htons(3490);
  server_info.sin_addr = *((struct in_addr *)he->h_addr);
  if (connect(socket_fd, (struct sockaddr *)&server_info,
              sizeof(struct sockaddr)) < 0) {
    perror("connect");
    exit(1);
  }
  while (1) {
    printf("Client started........\n");
    fgets(buffer, 1024 - 1, stdin);
    if ((send(socket_fd, buffer, strlen(buffer), 0)) == -1) {
      fprintf(stderr, "Failure Sending Message\n");
      close(socket_fd);
      exit(1);
    } else {
      printf("Message being sent: %s\n", buffer);
    }
  }
  close(socket_fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1212 <main+0x42>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    124c <main+0x7c>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    1290 <main+0xc0>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0xda2,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    12f6 <main+0x126>
lea    0xd59(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    12fb <main+0x12b>
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x430(%rbp),%rdi
mov    0x2cc9(%rip),%rax
mov    (%rax),%edx
mov    $0x3ff,%esi
call   1090 <fgets@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x83c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x430(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x83c(%rbp),%edi
mov    -0x838(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0xffffffff,%eax
jne    138c <main+0x1bc>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
lea    0xceb(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x430(%rbp),%rsi
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12fb <main+0x12b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
cmp    $0x2,%edi
jne    1214 <main+0x34>
mov    0x8(%rsi),%rdi
call   10b0 <gethostbyname@plt>
test   %rax,%rax
jne    1233 <main+0x53>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
jmp    1224 <main+0x44>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %rax,%r14
mov    0x2dab(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
jne    1267 <main+0x87>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
jmp    1224 <main+0x44>
mov    %eax,%r15d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0xda2,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r14),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10f0 <connect@plt>
test   %rax,%rax
jns    12c4 <main+0xe4>
lea    0xd8b(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xdae(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d09(%rip),%r12
mov    (%r12),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3ff,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xffffffff,%eax
je     1362 <main+0x182>
lea    0xd51(%rip),%r14
lea    0x10(%rsp),%rbp
lea    0xd5d(%rip),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%r12),%edx
mov    %rbp,%rdi
mov    $0x3ff,%esi
call   10a0 <fgets@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xffffffff,%eax
jne    1320 <main+0x140>
mov    0x2c67(%rip),%rax
mov    (%rax),%edi
lea    0xcd6(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %r15d,%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: client hostname\0A\00"
@.str.1 = [22 x i8] c"Cannot get host name\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [18 x i8] c"Socket Failure!!\0A\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [24 x i8] c"Client started........\0A\00"
@stdin = global i32 0
@.str.5 = [25 x i8] c"Failure Sending Message\0A\00"
@.str.6 = [24 x i8] c"Message being sent: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
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 %18
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))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call %struct.hostent* @gethostbyname(i8* %21)
store %struct.hostent* %22, %struct.hostent** %7
%23 = icmp eq %struct.hostent* %22, null
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %8
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %28
%38 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%39 = load i32, i32* @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %39, i32* %40
%41 = call i32 @htons(i32 3490)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%44 = load %struct.hostent*, %struct.hostent** %7
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %44, i32 0, i32 0
%46 = load i64, i64* %45
%47 = inttoptr i64 %46 to %struct.in_addr*
%48 = bitcast %struct.in_addr* %43 to i8*
%49 = bitcast %struct.in_addr* %47 to i8*
%50 = load i32, i32* %8
%51 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%52 = call i64 @connect(i32 %50, %struct.sockaddr* %51, i32 4)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %37
%55 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %37
br label %58
58: ; preds = %57, %78
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%61 = load i32, i32* @stdin
%62 = call i32 @fgets(i8* %60, i32 1023, i32 %61)
%63 = load i32, i32* %8
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = call i32 @send(i32 %63, i8* %64, i32 %66, i32 0)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %75
69: ; preds = %58
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%72 = load i32, i32* %8
%73 = call i32 @close(i32 %72)
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %58
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %75
br label %58
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: client hostname\0A\00"
@.str.1 = [22 x i8] c"Cannot get host name\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [18 x i8] c"Socket Failure!!\0A\00"
@.str.3 = [8 x i8] c"connect\00"
@stdin = global i32 0
@.str.5 = [25 x i8] c"Failure Sending Message\0A\00"
@.str.6 = [24 x i8] c"Message being sent: %s\0A\00"
@str = [23 x i8] c"Client started........\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.hostent* @gethostbyname(i8* %14)
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = tail call i32 @socket(i32 %22, i32 %23, i32 0)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %32, i32* %33
%34 = call i32 @htons(i32 3490)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %34, i32* %35
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%37 = load i64, i64* %36
%38 = inttoptr i64 %37 to i32*
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%40 = load i32, i32* %38
store i32 %40, i32* %39
%41 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%42 = call i64 @connect(i32 %24, %struct.sockaddr* %41, i32 4)
%43 = icmp slt i64 %42, 0
br i1 %43, label %51, label %44
44: ; preds = %30
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%46 = load i32, i32* @stdin
%47 = call i32 @fgets(i8* %6, i32 1023, i32 %46)
%48 = call i32 @strlen(i8* %6)
%49 = call i32 @send(i32 %24, i8* %6, i32 %48, i32 0)
%50 = icmp eq i32 %49, -1
br i1 %50, label %54, label %59
51: ; preds = %30
%52 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %59, %44
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%57 = call i32 @close(i32 %24)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %44, %59
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%62 = load i32, i32* @stdin
%63 = call i32 @fgets(i8* %6, i32 1023, i32 %62)
%64 = call i32 @strlen(i8* %6)
%65 = call i32 @send(i32 %24, i8* %6, i32 %64, i32 0)
%66 = icmp eq i32 %65, -1
br i1 %66, label %54, label %59
}