#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*/ uint64_t;
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;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ query_buffer(int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              char const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd, portno, n;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  int opt = 1;
  if (argc < 2) {
    fprintf(stderr, "usage %s port [hostname]\n", argv[0]);
    exit(0);
  }
  portno = atoi(argv[1]);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  if (argc == 2) {
    server = gethostbyname("localhost");
  } else {
    server = gethostbyname(argv[2]);
  }
  if (server == NULL) {
    fprintf(stderr, "ERROR, no such host\n");
    exit(0);
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
        server->h_length);
  serv_addr.sin_port = htons(portno);
  setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(int));
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    error("ERROR connecting");
  char buffer[256] = "The quick brown fox jumps over the lazy dog";
  printf("Client Buffer: %s\n", buffer);
  n = write(sockfd, buffer, strlen(buffer));
  if (n < 0)
    error("ERROR writing to socket");
  bzero(buffer, 256);
  n = read(sockfd, buffer, 255);
  if (n < 0)
    error("ERROR reading from socket");
  query_buffer((uint64_t)buffer, strlen(buffer));
  printf("%s\n", buffer);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x34(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    126f <main+0x4f>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12b1 <main+0x91>
lea    0xd6e(%rip),%rdi
call   10e0 <error@plt>
cmpl   $0x2,-0x8(%rbp)
jne    12d0 <main+0xb0>
lea    0xd6d(%rip),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
jmp    12e1 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    130a <main+0xea>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   10d0 <bcopy@plt>
mov    -0x18(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c94(%rip),%rax
mov    (%rax),%esi
mov    0x2c63(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
jge    1395 <main+0x175>
lea    0xcbe(%rip),%rdi
call   10e0 <error@plt>
lea    -0x140(%rbp),%rdi
lea    0xd0d(%rip),%rsi
mov    $0x100,%edx
call   10c0 <memcpy@plt>
lea    -0x140(%rbp),%rsi
lea    0xca4(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x14c(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x140(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x14c(%rbp),%edi
mov    -0x148(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1410 <main+0x1f0>
lea    0xc67(%rip),%rdi
call   10e0 <error@plt>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   10f0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xff,%edx
call   1090 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    144e <main+0x22e>
lea    0xc41(%rip),%rdi
call   10e0 <error@plt>
lea    -0x140(%rbp),%rax
mov    %eax,-0x150(%rbp)
lea    -0x140(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x150(%rbp),%edi
mov    %eax,%esi
call   1100 <query_buffer@plt>
lea    -0x140(%rbp),%rsi
lea    0xbec(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x120,%rsp
mov    %rsi,%rbp
movl   $0x1,0xc(%rsp)
cmp    $0x1,%edi
jle    13e1 <main+0x1c1>
mov    %edi,%ebx
mov    0x8(%rbp),%rdi
call   1110 <atoi@plt>
mov    %eax,%r14d
mov    0x2d88(%rip),%r12
mov    (%r12),%edi
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
js     1281 <main+0x61>
cmp    $0x2,%ebx
jne    1292 <main+0x72>
lea    0xdb0(%rip),%rdi
jmp    1296 <main+0x76>
lea    0xd92(%rip),%rdi
call   10e0 <error@plt>
cmp    $0x2,%ebx
je     1278 <main+0x58>
mov    0x10(%rbp),%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
je     1403 <main+0x1e3>
mov    %rax,%rbx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rsi
lea    0x14(%rsp),%rdi
mov    (%rbx),%edx
call   10d0 <memmove@plt>
mov    %r14d,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d04(%rip),%rax
mov    (%rax),%esi
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
test   %rax,%rax
jns    1323 <main+0x103>
lea    0xd30(%rip),%rdi
call   10e0 <error@plt>
lea    0xd86(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    $0x100,%edx
mov    %rbx,%rdi
call   10c0 <memcpy@plt>
lea    0xd1c(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
jns    1370 <main+0x150>
lea    0xd07(%rip),%rdi
call   10e0 <error@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10f0 <bzero@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1090 <read@plt>
test   %eax,%eax
jns    13a2 <main+0x182>
lea    0xced(%rip),%rdi
call   10e0 <error@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1100 <query_buffer@plt>
lea    0xcaf(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %r15d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xc0b(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
lea    0xc26(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"usage %s port [hostname]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.4 = [17 x i8] c"ERROR connecting\00"
@__const.main.buffer = [256 x i8] c"The quick brown fox jumps over the lazy dog\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.5 = [19 x i8] c"Client Buffer: %s\0A\00"
@.str.6 = [24 x i8] c"ERROR writing to socket\00"
@.str.7 = [26 x i8] c"ERROR reading from socket\00"
@.str.8 = [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 i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.hostent*
%11 = alloca i32
%12 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %11
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %7
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %22
%33 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %22
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 2
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store %struct.hostent* %38, %struct.hostent** %10
br label %44
39: ; preds = %34
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call %struct.hostent* @gethostbyname(i8* %42)
store %struct.hostent* %43, %struct.hostent** %10
br label %44
44: ; preds = %39, %37
%45 = load %struct.hostent*, %struct.hostent** %10
%46 = icmp eq %struct.hostent* %45, null
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %44
%52 = bitcast %struct.sockaddr_in* %9 to i8*
%53 = call i32 @bzero(i8* %52, i32 12)
%54 = load i32, i32* @AF_INET
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %54, i32* %55
%56 = load %struct.hostent*, %struct.hostent** %10
%57 = getelementptr inbounds %struct.hostent, %struct.hostent* %56, i32 0, i32 1
%58 = load i64, i64* %57
%59 = inttoptr i64 %58 to i8*
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%61 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %60, i32 0, i32 0
%62 = bitcast i32* %61 to i8*
%63 = load %struct.hostent*, %struct.hostent** %10
%64 = getelementptr inbounds %struct.hostent, %struct.hostent* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i32 @bcopy(i8* %59, i8* %62, i32 %65)
%67 = load i32, i32* %7
%68 = call i32 @htons(i32 %67)
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %68, i32* %69
%70 = load i32, i32* %6
%71 = load i32, i32* @SOL_SOCKET
%72 = load i32, i32* @SO_REUSEADDR
%73 = bitcast i32* %11 to i8*
%74 = call i32 @setsockopt(i32 %70, i32 %71, i32 %72, i8* %73, i32 4)
%75 = load i32, i32* %6
%76 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%77 = call i64 @connect(i32 %75, %struct.sockaddr* %76, i32 12)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %51
%80 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %81
81: ; preds = %79, %51
%82 = bitcast [256 x i8]* %12 to i8*
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%84 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %83)
%85 = load i32, i32* %6
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%88 = call i32 @strlen(i8* %87)
%89 = call i32 @write(i32 %85, i8* %86, i32 %88)
store i32 %89, i32* %8
%90 = load i32, i32* %8
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %81
%93 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %94
94: ; preds = %92, %81
%95 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%96 = call i32 @bzero(i8* %95, i32 256)
%97 = load i32, i32* %6
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%99 = call i32 @read(i32 %97, i8* %98, i32 255)
store i32 %99, i32* %8
%100 = load i32, i32* %8
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %94
%103 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
br label %104
104: ; preds = %102, %94
%105 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%106 = ptrtoint i8* %105 to i32
%107 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%108 = call i32 @strlen(i8* %107)
%109 = call i32 @query_buffer(i32 %106, i32 %108)
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%111 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %110)
%112 = load i32, i32* %6
%113 = call i32 @close(i32 %112)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"usage %s port [hostname]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.4 = [17 x i8] c"ERROR connecting\00"
@__const.main.buffer = [256 x i8] c"The quick brown fox jumps over the lazy dog\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.5 = [19 x i8] c"Client Buffer: %s\0A\00"
@.str.6 = [24 x i8] c"ERROR writing to socket\00"
@.str.7 = [26 x i8] c"ERROR reading from socket\00"
@.str.8 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %14
%25 = icmp eq i32 %0, 2
br i1 %25, label %29, label %26
26: ; preds = %24
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
br label %29
29: ; preds = %24, %26
%30 = phi i8* [ %28, %26 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %24 ]
%31 = tail call %struct.hostent* @gethostbyname(i8* %30)
%32 = icmp eq %struct.hostent* %31, null
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%36 = tail call i32 @exit(i32 0)
unreachable
37: ; preds = %29
%38 = call i32 @bzero(i8* %6, i32 12)
%39 = load i32, i32* @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %39, i32* %40
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i64 0, i32 1
%42 = load i64, i64* %41
%43 = inttoptr i64 %42 to i8*
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%45 = bitcast i32* %44 to i8*
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i64 0, i32 0
%47 = load i32, i32* %46
%48 = tail call i32 @htons(i32 %17)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %48, i32* %49
%50 = load i32, i32* @SOL_SOCKET
%51 = load i32, i32* @SO_REUSEADDR
%52 = call i32 @setsockopt(i32 %20, i32 %50, i32 %51, i8* %7, i32 4)
%53 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%54 = call i64 @connect(i32 %20, %struct.sockaddr* %53, i32 12)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %37
%57 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %58
58: ; preds = %56, %37
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%60 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %59)
%61 = call i32 @strlen(i8* %59)
%62 = call i32 @write(i32 %20, i8* %59, i32 %61)
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %58
%65 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %64, %58
%67 = call i32 @bzero(i8* %59, i32 256)
%68 = call i32 @read(i32 %20, i8* %59, i32 255)
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
br label %72
72: ; preds = %70, %66
%73 = ptrtoint [256 x i8]* %5 to i64
%74 = trunc i64 %73 to i32
%75 = call i32 @strlen(i8* %59)
%76 = call i32 @query_buffer(i32 %74, i32 %75)
%77 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %59)
%78 = call i32 @close(i32 %20)
ret i32 0
}