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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int canLoop = 1;
  int sockfd;
  int n;
  int port;
  int interval;
  char data[10000];
  char response[10000];
  struct sockaddr_in servaddr;
  struct sockaddr_in cliaddr;
  if (argc != 3) {
    printf("usage:  client <IP address> <port number>\n");
    return 1;
  }
  sscanf(argv[2], "%d", &port);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = inet_addr(argv[1]);
  servaddr.sin_port = htons(port);
  connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  while (fgets(data, 10000, stdin) != NULL) {
    sendto(sockfd, data, strlen(data), 0, (struct sockaddr *)&servaddr,
           sizeof(servaddr));
    n = recvfrom(sockfd, response, 10000, 0, NULL, NULL);
    response[n] = 0;
    fputs(strcat(response, "\n"), stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1212 <main+0x42>
lea    0xdff(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1361 <main+0x191>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0a(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   10b0 <sscanf@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x18(%rbp)
lea    -0x4e60(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4e58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x4e5c(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x4e60(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x4e60(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
lea    -0x2740(%rbp),%rdi
mov    0x2d37(%rip),%rax
mov    (%rax),%edx
mov    $0x2710,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     135a <main+0x18a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4e7c(%rbp)
lea    -0x2740(%rbp),%rax
mov    %rax,-0x4e78(%rbp)
lea    -0x2740(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4e7c(%rbp),%edi
mov    -0x4e78(%rbp),%rsi
mov    %eax,%edx
lea    -0x4e60(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    -0x18(%rbp),%edi
lea    -0x4e50(%rbp),%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10a0 <recvfrom@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x4e50(%rbp,%rax,1)
lea    -0x4e50(%rbp),%rdi
lea    0xce9(%rip),%rsi
call   10d0 <strcat@plt>
mov    %eax,%edi
mov    0x2c7a(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
jmp    129b <main+0xcb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4e80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e48,%rsp
cmp    $0x3,%edi
jne    1325 <main+0x155>
mov    %rsi,%rbp
mov    0x10(%rsi),%rdi
lea    0xe08(%rip),%rsi
lea    0xc(%rsp),%rdx
call   10b0 <sscanf@plt>
mov    0x2ddf(%rip),%r12
mov    (%r12),%edi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    0xc(%rsp),%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
lea    0x2730(%rsp),%rdi
mov    $0x2710,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     1336 <main+0x166>
lea    0x2730(%rsp),%rbp
lea    0x20(%rsp),%r12
lea    0xd65(%rip),%r13
mov    0x2d23(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1040 <strlen@plt>
xor    %ebx,%ebx
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
lea    0x10(%rsp),%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
call   10d0 <strcat@plt>
mov    (%r15),%esi
mov    %eax,%edi
call   1060 <fputs@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x2710,%esi
call   1080 <fgets@plt>
test   %rax,%rax
jne    12b0 <main+0xe0>
jmp    1336 <main+0x166>
lea    0xcd9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x4e48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [43 x i8] c"usage: client <IP address> <port number>\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stdin = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [10000 x i8]
%12 = alloca [10000 x i8]
%13 = alloca %struct.sockaddr_in
%14 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %65
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %7
%27 = call i32 @bzero(%struct.sockaddr_in* %13, i32 12)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %28, i32* %29
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @inet_addr(i8* %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i32 %33, i32* %35
%36 = load i32, i32* %9
%37 = call i32 @htons(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
store i32 %37, i32* %38
%39 = load i32, i32* %7
%40 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%41 = call i32 @connect(i32 %39, %struct.sockaddr* %40, i32 12)
br label %42
42: ; preds = %47, %19
%43 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 0
%44 = load i32, i32* @stdin
%45 = call i32* @fgets(i8* %43, i32 10000, i32 %44)
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %64
47: ; preds = %42
%48 = load i32, i32* %7
%49 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 0
%50 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 0
%51 = call i32 @strlen(i8* %50)
%52 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%53 = call i32 @sendto(i32 %48, i8* %49, i32 %51, i32 0, %struct.sockaddr* %52, i32 12)
%54 = load i32, i32* %7
%55 = getelementptr inbounds [10000 x i8], [10000 x i8]* %12, i64 0, i64 0
%56 = call i32 @recvfrom(i32 %54, i8* %55, i32 10000, i32 0, i32* null, i32* null)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [10000 x i8], [10000 x i8]* %12, i64 0, i64 %58
store i8 0, i8* %59
%60 = getelementptr inbounds [10000 x i8], [10000 x i8]* %12, i64 0, i64 0
%61 = call i32 @strcat(i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%62 = load i32, i32* @stdout
%63 = call i32 @fputs(i32 %61, i32 %62)
br label %42
64: ; preds = %42
store i32 0, i32* %3
br label %65
65: ; preds = %64, %17
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [3 x i8] c"%d\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stdin = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
@stdout = global i32 0
@str = [42 x i8] c"usage: client <IP address> <port number>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [10000 x i8]
%5 = alloca [10000 x i8]
%6 = alloca %struct.sockaddr_in
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %48
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @inet_addr(i8* %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* %3
%29 = call i32 @htons(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i32 %29, i32* %30
%31 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%32 = call i32 @connect(i32 %20, %struct.sockaddr* %31, i32 12)
%33 = load i32, i32* @stdin
%34 = call i32* @fgets(i8* %8, i32 10000, i32 %33)
%35 = icmp eq i32* %34, null
br i1 %35, label %48, label %36
36: ; preds = %14, %36
%37 = call i32 @strlen(i8* %8)
%38 = call i32 @sendto(i32 %20, i8* %8, i32 %37, i32 0, %struct.sockaddr* %31, i32 12)
%39 = call i32 @recvfrom(i32 %20, i8* %9, i32 10000, i32 0, i32* null, i32* null)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @stdout
%44 = call i32 @fputs(i32 %42, i32 %43)
%45 = load i32, i32* @stdin
%46 = call i32* @fgets(i8* %8, i32 10000, i32 %45)
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %36
48: ; preds = %36, %14, %12
%49 = phi i32 [ 1, %12 ], [ 0, %14 ], [ 0, %36 ]
ret i32 %49
}