#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;
  scalar_t__ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addrtype;
  scalar_t__ *h_addr_list;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fwrite(char *, scalar_t__, int, int /*<<< orphan*/);
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ h_errno;
char *hstrerror(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, char *, int);
int socket(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char const *);
scalar_t__ write(int, char const *, scalar_t__);
int main(int argc, char *argv[]) {
  const char query[] = "GET / HTTP/1.0\r\n"
                       "Host: www.baidu.com\r\n"
                       "\r\n";
  const char hostname[] = "www.baidu.com";
  struct sockaddr_in serv_addr;
  struct hostent *host;
  const char *cp;
  int fd, i;
  ssize_t n_bytes, remaining;
  char buf[1024];
  host = gethostbyname(hostname);
  if (host == NULL) {
    fprintf(stderr, "Couldn't lookup %s: %s\n", hostname, hstrerror(h_errno));
    exit(EXIT_FAILURE);
  }
  if (host->h_addrtype != AF_INET) {
    fprintf(stderr, "No ipv6 support, sorry\n");
    exit(EXIT_FAILURE);
  }
  fd = socket(AF_INET, SOCK_STREAM, 0);
  if (fd == -1) {
    perror("socket() failed");
    exit(EXIT_FAILURE);
  }
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(80);
  for (i = 0; host->h_addr_list[i]; ++i) {
    serv_addr.sin_addr = *(struct in_addr *)host->h_addr_list[i];
    break;
  }
  if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1) {
    perror("connect() failed");
    close(fd);
    exit(EXIT_FAILURE);
  }
  cp = query;
  remaining = strlen(query);
  while (remaining) {
    n_bytes = write(fd, cp, remaining);
    if (n_bytes <= 0) {
      perror("write() failed");
      exit(EXIT_FAILURE);
    }
    remaining -= n_bytes;
    cp += n_bytes;
  }
  while (1) {
    n_bytes = read(fd, buf, sizeof(buf));
    if (n_bytes == 0) {
      break;
    } else if (n_bytes < 0) {
      perror("read() failed");
      close(fd);
      exit(EXIT_FAILURE);
    }
    fwrite(buf, n_bytes, 1, stdout);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xdec(%rip),%rsi
mov    $0x28,%edx
call   10b0 <memcpy@plt>
mov    0xe03(%rip),%rax
mov    %rax,-0x4e(%rbp)
mov    0xe01(%rip),%eax
mov    %eax,-0x46(%rbp)
mov    0xdfb(%rip),%ax
mov    %ax,-0x42(%rbp)
lea    -0x4e(%rbp),%rdi
call   1090 <gethostbyname@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    12a9 <main+0xb9>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x49c(%rbp)
lea    -0x4e(%rbp),%rax
mov    %rax,-0x498(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   10d0 <hstrerror@plt>
mov    -0x49c(%rbp),%edi
mov    -0x498(%rbp),%rdx
mov    %rax,%rcx
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x68(%rbp),%rax
mov    (%rax),%rax
mov    0x2d31(%rip),%rcx
cmp    (%rcx),%rax
je     12e5 <main+0xf5>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%rdi
mov    0x2cd2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
jne    1326 <main+0x136>
lea    0xd53(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %eax,-0x5c(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x68(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x78(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1384 <main+0x194>
mov    -0x68(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x74(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x10,%edx
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
jne    13c0 <main+0x1d0>
lea    0xcd1(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x74(%rbp),%edi
call   1070 <close@plt>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     1448 <main+0x258>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rsi
mov    -0x88(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jg     1422 <main+0x232>
lea    0xc78(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ba5(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x80(%rbp),%rcx
mov    -0x88(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x88(%rbp)
mov    -0x80(%rbp),%rax
add    -0x70(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    13d8 <main+0x1e8>
jmp    144d <main+0x25d>
mov    -0x74(%rbp),%edi
lea    -0x490(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jne    1475 <main+0x285>
jmp    14ca <main+0x2da>
cmpq   $0x0,-0x80(%rbp)
jge    14a2 <main+0x2b2>
lea    0xc0f(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x74(%rbp),%edi
call   1070 <close@plt>
mov    0x2b25(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    14a7 <main+0x2b7>
lea    -0x490(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    0x2aff(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1100 <fwrite@plt>
jmp    144d <main+0x25d>
mov    -0x74(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x458,%rsp
movaps 0xe1c(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe00(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movabs $0xa0d0a0d6d6f63,%rax
mov    %rax,0x40(%rsp)
movabs $0x6d6f632e756469,%rax
mov    %rax,0x16(%rsp)
movabs $0x646961622e777777,%rax
61 69 64
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1090 <gethostbyname@plt>
test   %rax,%rax
je     1395 <main+0x1b5>
mov    %rax,%r14
mov    (%rax),%rdi
mov    0x2d96(%rip),%rbx
cmp    (%rbx),%rdi
jne    13c6 <main+0x1e6>
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     13df <main+0x1ff>
mov    %eax,%r15d
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    (%rbx),%rax
mov    %rax,0x8(%rsp)
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rax
mov    (%rax),%rax
test   %rax,%rax
je     12ad <main+0xcd>
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x10,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     13e8 <main+0x208>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     12fb <main+0x11b>
mov    %rax,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <write@plt>
test   %rax,%rax
jle    1365 <main+0x185>
add    %rax,%rbx
sub    %rax,%rbp
jne    12e0 <main+0x100>
lea    0x50(%rsp),%rsi
mov    %r15d,%edi
mov    $0x400,%edx
call   1080 <read@plt>
test   %rax,%rax
je     134d <main+0x16d>
mov    0x2c9f(%rip),%rbp
lea    0x50(%rsp),%rbx
xchg   %ax,%ax
test   %rax,%rax
js     1373 <main+0x193>
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   10f0 <fwrite@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
test   %rax,%rax
jne    1320 <main+0x140>
mov    %r15d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x458,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd1b(%rip),%rdi
call   10b0 <perror@plt>
jmp    1387 <main+0x1a7>
lea    0xd1c(%rip),%rdi
call   10b0 <perror@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x2c34(%rip),%rax
mov    (%rax),%ebx
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
call   10c0 <hstrerror@plt>
lea    0xc83(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1387 <main+0x1a7>
mov    0x2c03(%rip),%rax
mov    (%rax),%edi
lea    0xc78(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1387 <main+0x1a7>
lea    0xc80(%rip),%rdi
jmp    136c <main+0x18c>
lea    0xc87(%rip),%rdi
jmp    137a <main+0x19a>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i64 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64, i64* }
%struct.sockaddr = type { i32 }
@__const.main.query = [40 x i8] c"GET / HTTP/1.0\0D\0AHost: www.baidu.com\0D\0A\0D\0A\00"
@__const.main.hostname = [14 x i8] c"www.baidu.com\00"
@stderr = global i32 0
@.str = [24 x i8] c"Couldn't lookup %s: %s\0A\00"
@h_errno = global i32 0
@EXIT_FAILURE = global i32 0
@AF_INET = global i64 0
@.str.1 = [24 x i8] c"No ipv6 support, sorry\0A\00"
@SOCK_STREAM = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@.str.3 = [17 x i8] c"connect() failed\00"
@.str.4 = [15 x i8] c"write() failed\00"
@.str.5 = [14 x i8] c"read() failed\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [40 x i8]
%7 = alloca [14 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.hostent*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = bitcast [40 x i8]* %6 to i8*
%17 = bitcast [14 x i8]* %7 to i8*
%18 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%19 = call %struct.hostent* @gethostbyname(i8* %18)
store %struct.hostent* %19, %struct.hostent** %9
%20 = load %struct.hostent*, %struct.hostent** %9
%21 = icmp eq %struct.hostent* %20, null
br i1 %21, label %22, label %30
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* @h_errno
%26 = call i8* @hstrerror(i32 %25)
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %2
%31 = load %struct.hostent*, %struct.hostent** %9
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = load i64, i64* @AF_INET
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %30
%42 = load i64, i64* @AF_INET
%43 = load i32, i32* @SOCK_STREAM
%44 = call i32 @socket(i64 %42, i32 %43, i32 0)
store i32 %44, i32* %11
%45 = load i32, i32* %11
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %41
%48 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %41
%52 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 16)
%53 = load i64, i64* @AF_INET
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i64 %53, i64* %54
%55 = call i32 @htons(i32 80)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %55, i32* %56
store i32 0, i32* %12
br label %57
57: ; preds = %78, %51
%58 = load %struct.hostent*, %struct.hostent** %9
%59 = getelementptr inbounds %struct.hostent, %struct.hostent* %58, i32 0, i32 1
%60 = load i64*, i64** %59
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i64, i64* %60, i64 %62
%64 = load i64, i64* %63
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %81
66: ; preds = %57
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%68 = load %struct.hostent*, %struct.hostent** %9
%69 = getelementptr inbounds %struct.hostent, %struct.hostent* %68, i32 0, i32 1
%70 = load i64*, i64** %69
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i64, i64* %70, i64 %72
%74 = load i64, i64* %73
%75 = inttoptr i64 %74 to %struct.in_addr*
%76 = bitcast %struct.in_addr* %67 to i8*
%77 = bitcast %struct.in_addr* %75 to i8*
br label %81
78: ; No predecessors!
%79 = load i32, i32* %12
%80 = add nsw i32 %79, 1
store i32 %80, i32* %12
br label %57
81: ; preds = %66, %57
%82 = load i32, i32* %11
%83 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%84 = call i32 @connect(i32 %82, %struct.sockaddr* %83, i32 16)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %92
86: ; preds = %81
%87 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%88 = load i32, i32* %11
%89 = call i32 @close(i32 %88)
%90 = load i32, i32* @EXIT_FAILURE
%91 = call i32 @exit(i32 %90)
unreachable
92: ; preds = %81
%93 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
store i8* %93, i8** %10
%94 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%95 = call i64 @strlen(i8* %94)
store i64 %95, i64* %14
br label %96
96: ; preds = %110, %92
%97 = load i64, i64* %14
%98 = icmp ne i64 %97, 0
br i1 %98, label %99, label %117
99: ; preds = %96
%100 = load i32, i32* %11
%101 = load i8*, i8** %10
%102 = load i64, i64* %14
%103 = call i64 @write(i32 %100, i8* %101, i64 %102)
store i64 %103, i64* %13
%104 = load i64, i64* %13
%105 = icmp sle i64 %104, 0
br i1 %105, label %106, label %110
106: ; preds = %99
%107 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%108 = load i32, i32* @EXIT_FAILURE
%109 = call i32 @exit(i32 %108)
unreachable
110: ; preds = %99
%111 = load i64, i64* %13
%112 = load i64, i64* %14
%113 = sub nsw i64 %112, %111
store i64 %113, i64* %14
%114 = load i64, i64* %13
%115 = load i8*, i8** %10
%116 = getelementptr inbounds i8, i8* %115, i64 %114
store i8* %116, i8** %10
br label %96
117: ; preds = %96
br label %118
118: ; preds = %117, %135
%119 = load i32, i32* %11
%120 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%121 = call i64 @read(i32 %119, i8* %120, i32 1024)
store i64 %121, i64* %13
%122 = load i64, i64* %13
%123 = icmp eq i64 %122, 0
br i1 %123, label %124, label %125
124: ; preds = %118
br label %140
125: ; preds = %118
%126 = load i64, i64* %13
%127 = icmp slt i64 %126, 0
br i1 %127, label %128, label %134
128: ; preds = %125
%129 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%130 = load i32, i32* %11
%131 = call i32 @close(i32 %130)
%132 = load i32, i32* @EXIT_FAILURE
%133 = call i32 @exit(i32 %132)
unreachable
134: ; preds = %125
br label %135
135: ; preds = %134
%136 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%137 = load i64, i64* %13
%138 = load i32, i32* @stdout
%139 = call i32 @fwrite(i8* %136, i64 %137, i32 1, i32 %138)
br label %118
140: ; preds = %124
%141 = load i32, i32* %11
%142 = call i32 @close(i32 %141)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i64 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64, i64* }
%struct.sockaddr = type { i32 }
@__const.main.query = [40 x i8] c"GET / HTTP/1.0\0D\0AHost: www.baidu.com\0D\0A\0D\0A\00"
@__const.main.hostname = [14 x i8] c"www.baidu.com\00"
@stderr = global i32 0
@.str = [24 x i8] c"Couldn't lookup %s: %s\0A\00"
@h_errno = global i32 0
@EXIT_FAILURE = global i32 0
@AF_INET = global i64 0
@.str.1 = [24 x i8] c"No ipv6 support, sorry\0A\00"
@SOCK_STREAM = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@.str.3 = [17 x i8] c"connect() failed\00"
@.str.4 = [15 x i8] c"write() failed\00"
@.str.5 = [14 x i8] c"read() failed\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [40 x i8]
%4 = alloca [14 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = call %struct.hostent* @gethostbyname(i8* %8)
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @h_errno
%16 = call i8* @hstrerror(i32 %15)
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* @AF_INET
%24 = icmp eq i64 %22, %23
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %20
%31 = load i32, i32* @SOCK_STREAM
%32 = call i32 @socket(i64 %22, i32 %31, i32 0)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %30
%39 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 16)
%40 = load i64, i64* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i64 %40, i64* %41
%42 = call i32 @htons(i32 80)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %42, i32* %43
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 1
%45 = load i64*, i64** %44
%46 = load i64, i64* %45
%47 = icmp eq i64 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %38
%49 = inttoptr i64 %46 to i32*
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
%51 = load i32, i32* %49
store i32 %51, i32* %50
br label %52
52: ; preds = %48, %38
%53 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%54 = call i32 @connect(i32 %32, %struct.sockaddr* %53, i32 16)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @close(i32 %32)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %52
%62 = call i64 @strlen(i8* %7)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %76, %61
%65 = call i64 @read(i32 %32, i8* %10, i32 1024)
%66 = icmp eq i64 %65, 0
br i1 %66, label %93, label %80
67: ; preds = %61, %76
%68 = phi i64 [ %77, %76 ], [ %62, %61 ]
%69 = phi i8* [ %78, %76 ], [ %7, %61 ]
%70 = call i64 @write(i32 %32, i8* %69, i64 %68)
%71 = icmp slt i64 %70, 1
br i1 %71, label %72, label %76
72: ; preds = %67
%73 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %67
%77 = sub nsw i64 %68, %70
%78 = getelementptr inbounds i8, i8* %69, i64 %70
%79 = icmp eq i64 %77, 0
br i1 %79, label %64, label %67
80: ; preds = %64, %88
%81 = phi i64 [ %91, %88 ], [ %65, %64 ]
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%85 = call i32 @close(i32 %32)
%86 = load i32, i32* @EXIT_FAILURE
%87 = call i32 @exit(i32 %86)
unreachable
88: ; preds = %80
%89 = load i32, i32* @stdout
%90 = call i32 @fwrite(i8* %10, i64 %81, i32 1, i32 %89)
%91 = call i64 @read(i32 %32, i8* %10, i32 1024)
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %80
93: ; preds = %88, %64
%94 = call i32 @close(i32 %32)
ret i32 0
}