#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 {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_NUMERICHOST;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int main(int argc, char **argv) {
  struct addrinfo *result = NULL;
  struct addrinfo hints;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = AI_NUMERICHOST;
  int rc = getaddrinfo(argv[1], argv[2], &hints, &result);
  int tcp_socket = socket(result->ai_family, result->ai_socktype, 0);
  connect(tcp_socket, (struct sockaddr *)result->ai_addr, result->ai_addrlen);
  freeaddrinfo(result);
  char buf[80];
  scanf("%s", buf);
  int bytes = strlen(buf);
  while (!(bytes == 1 && buf[0] == 'Q')) {
    send(tcp_socket, buf, bytes, 0);
    bytes = recv(tcp_socket, buf, 79, 0);
    buf[bytes] = '\0';
    printf("%s\n", buf);
    scanf("%s", buf);
    bytes = strlen(buf);
  }
  close(tcp_socket);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   10b0 <getaddrinfo@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   10a0 <connect@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
lea    -0x90(%rbp),%rsi
lea    0xd96(%rip),%rdi
call   1090 <scanf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x94(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x94(%rbp)
mov    %al,-0x95(%rbp)
jne    12a9 <main+0xf9>
movsbl -0x90(%rbp),%eax
cmp    $0x51,%eax
sete   %al
mov    %al,-0x95(%rbp)
mov    -0x95(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    12be <main+0x10e>
jmp    133d <main+0x18d>
mov    -0x40(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0x94(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x40(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x4f,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x94(%rbp)
movslq -0x94(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rsi
lea    0xcf5(%rip),%rdi
call   1060 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xcdf(%rip),%rdi
call   1090 <scanf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x94(%rbp)
jmp    1281 <main+0xd1>
mov    -0x40(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
lea    0x8(%rsp),%rcx
mov    %rbp,%rdx
call   10b0 <getaddrinfo@plt>
mov    0x8(%rsp),%rax
mov    0x10(%rax),%esi
mov    0x14(%rax),%edi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rsi
mov    (%rax),%edx
mov    %ebp,%edi
call   10a0 <connect@plt>
mov    0x8(%rsp),%rdi
call   10c0 <freeaddrinfo@plt>
lea    0xdb0(%rip),%rdi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    1271 <main+0xc1>
cmpb   $0x51,0x30(%rsp)
je     12e0 <main+0x130>
lea    0x30(%rsp),%rbx
lea    0xd86(%rip),%r14
lea    0xd7c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4f,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    1290 <main+0xe0>
cmpb   $0x51,0x30(%rsp)
jne    1290 <main+0xe0>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_NUMERICHOST = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.addrinfo
%8 = alloca i32
%9 = alloca i32
%10 = alloca [80 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.addrinfo* null, %struct.addrinfo** %6
%12 = call i32 @memset(%struct.addrinfo* %7, i32 0, i32 32)
%13 = load i32, i32* @AF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_DGRAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* @AI_NUMERICHOST
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 4
store i32 %17, i32* %18
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @getaddrinfo(i8* %21, i8* %24, %struct.addrinfo* %7, %struct.addrinfo** %6)
store i32 %25, i32* %8
%26 = load %struct.addrinfo*, %struct.addrinfo** %6
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i32 0, i32 3
%28 = load i32, i32* %27
%29 = load %struct.addrinfo*, %struct.addrinfo** %6
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i32 0, i32 2
%31 = load i32, i32* %30
%32 = call i32 @socket(i32 %28, i32 %31, i32 0)
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = load %struct.addrinfo*, %struct.addrinfo** %6
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 1
%36 = load i64, i64* %35
%37 = inttoptr i64 %36 to %struct.sockaddr*
%38 = load %struct.addrinfo*, %struct.addrinfo** %6
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @connect(i32 %33, %struct.sockaddr* %37, i32 %40)
%42 = load %struct.addrinfo*, %struct.addrinfo** %6
%43 = call i32 @freeaddrinfo(%struct.addrinfo* %42)
%44 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %44)
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
store i32 %47, i32* %11
br label %48
48: ; preds = %59, %2
%49 = load i32, i32* %11
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 81
br label %56
56: ; preds = %51, %48
%57 = phi i1 [ false, %48 ], [ %55, %51 ]
%58 = xor i1 %57, true
br i1 %58, label %59, label %76
59: ; preds = %56
%60 = load i32, i32* %9
%61 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%62 = load i32, i32* %11
%63 = call i32 @send(i32 %60, i8* %61, i32 %62, i32 0)
%64 = load i32, i32* %9
%65 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%66 = call i32 @recv(i32 %64, i8* %65, i32 79, i32 0)
store i32 %66, i32* %11
%67 = load i32, i32* %11
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 %68
store i8 0, i8* %69
%70 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%71 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %70)
%72 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%73 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %72)
%74 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%75 = call i32 @strlen(i8* %74)
store i32 %75, i32* %11
br label %48
76: ; preds = %56
%77 = load i32, i32* %9
%78 = call i32 @close(i32 %77)
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_NUMERICHOST = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo
%5 = alloca [80 x i8]
%6 = bitcast %struct.addrinfo** %3 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %3
%7 = bitcast %struct.addrinfo* %4 to i8*
%8 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 32)
%9 = load i32, i32* @AF_UNSPEC
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %9, i32* %10
%11 = load i32, i32* @SOCK_DGRAM
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @AI_NUMERICHOST
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %13, i32* %14
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @getaddrinfo(i8* %16, i8* %18, %struct.addrinfo* %4, %struct.addrinfo** %3)
%20 = load %struct.addrinfo*, %struct.addrinfo** %3
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i64 0, i32 3
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i64 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 @socket(i32 %22, i32 %24, i32 0)
%26 = load %struct.addrinfo*, %struct.addrinfo** %3
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 1
%28 = load i64, i64* %27
%29 = inttoptr i64 %28 to %struct.sockaddr*
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @connect(i32 %25, %struct.sockaddr* %29, i32 %31)
%33 = load %struct.addrinfo*, %struct.addrinfo** %3
%34 = call i32 @freeaddrinfo(%struct.addrinfo* %33)
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = call i32 @strlen(i8* %35)
%38 = icmp ne i32 %37, 1
%39 = load i8, i8* %35
%40 = icmp ne i8 %39, 81
%41 = select i1 %38, i1 true, i1 %40
br i1 %41, label %42, label %55
42: ; preds = %2, %42
%43 = phi i32 [ %50, %42 ], [ %37, %2 ]
%44 = call i32 @send(i32 %25, i8* %35, i32 %43, i32 0)
%45 = call i32 @recv(i32 %25, i8* %35, i32 79, i32 0)
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %46
store i8 0, i8* %47
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%49 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %35)
%50 = call i32 @strlen(i8* %35)
%51 = icmp ne i32 %50, 1
%52 = load i8, i8* %35
%53 = icmp ne i8 %52, 81
%54 = select i1 %51, i1 true, i1 %53
br i1 %54, label %42, label %55
55: ; preds = %42, %2
%56 = call i32 @close(i32 %25)
ret i32 0
}