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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  struct hostent *host;
  int port;
  int soc;
  struct sockaddr_in target_addr;
  char request_str[1024];
  int send_len;
  char response_buf[4096];
  int recv_len;
  if (argc != 4) {
    printf("Not enough input arguments.\n");
    return -1;
  }
  host = gethostbyname(argv[1]);
  if (host == NULL) {
    printf("gethostbyname error!\n");
    return -2;
  }
  port = atoi(argv[2]);
  soc = socket(AF_INET, SOCK_STREAM, 0);
  if (soc == -1) {
    printf("socket error!\n");
    return -3;
  }
  target_addr.sin_family = AF_INET;
  target_addr.sin_port = htons(port);
  target_addr.sin_addr.s_addr = *(in_addr_t *)host->h_addr_list[0];
  if (connect(soc, (struct sockaddr *)&target_addr, sizeof(target_addr)) ==
      -1) {
    printf("connect error!\n");
    close(soc);
    return -4;
  }
  printf("connect success.\n");
  memset(request_str, 0, sizeof(char) * 1024);
  sprintf(request_str, "GET %s HTTP/1.0\r\n\r\n", argv[3]);
  send_len = send(soc, request_str, strlen(request_str), 0);
  memset(response_buf, 0, sizeof(char) * 4096);
  recv_len = recv(soc, response_buf, sizeof(char) * 4096, 0);
  printf("%s\n", response_buf);
  close(soc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11fd <main+0x3d>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b3 <main+0x1f3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1233 <main+0x73>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    13b3 <main+0x1f3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1283 <main+0xc3>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    13b3 <main+0x1f3>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
jne    12e5 <main+0x125>
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    13b3 <main+0x1f3>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xd48(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1454(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x1450(%rbp)
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1454(%rbp),%edi
mov    -0x1450(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x434(%rbp)
lea    -0x1440(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
mov    -0x20(%rbp),%edi
lea    -0x1440(%rbp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1444(%rbp)
lea    -0x1440(%rbp),%rsi
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1410,%rsp
cmp    $0x4,%edi
jne    12e3 <main+0x123>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
je     12f6 <main+0x136>
mov    %rax,%rbp
mov    0x10(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r15d
mov    0x2de5(%rip),%r12
mov    (%r12),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     1309 <main+0x149>
mov    %eax,%r14d
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    %r15d,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x0(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     131c <main+0x15c>
lea    0xdb1(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%r15
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    0x18(%rbx),%rdx
lea    0xd77(%rip),%rsi
mov    %r15,%rdi
call   10c0 <sprintf@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    0x410(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   1090 <close@plt>
jmp    1335 <main+0x175>
lea    0xd6d(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
jmp    1335 <main+0x175>
lea    0xd45(%rip),%rdi
call   1040 <puts@plt>
mov    $0xfffffffe,%ebp
jmp    1335 <main+0x175>
lea    0xd24(%rip),%rdi
call   1040 <puts@plt>
mov    $0xfffffffd,%ebp
jmp    1335 <main+0x175>
lea    0xd02(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    $0xfffffffc,%ebp
mov    %ebp,%eax
add    $0x1410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [29 x i8] c"Not enough input arguments.\0A\00"
@.str.1 = [22 x i8] c"gethostbyname error!\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [15 x i8] c"socket error!\0A\00"
@.str.3 = [16 x i8] c"connect error!\0A\00"
@.str.4 = [18 x i8] c"connect success.\0A\00"
@.str.5 = [20 x i8] c"GET %s HTTP/1.0\0D\0A\0D\0A\00"
@.str.6 = [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.hostent*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca [4096 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %85
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** %6
%23 = load %struct.hostent*, %struct.hostent** %6
%24 = icmp eq %struct.hostent* %23, null
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %85
27: ; preds = %18
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %7
%32 = load i32, i32* @AF_INET
%33 = load i32, i32* @SOCK_STREAM
%34 = call i32 @socket(i32 %32, i32 %33, i32 0)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -3, i32* %3
br label %85
39: ; preds = %27
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %40, i32* %41
%42 = load i32, i32* %7
%43 = call i32 @htons(i32 %42)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %43, i32* %44
%45 = load %struct.hostent*, %struct.hostent** %6
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %45, i32 0, i32 0
%47 = load i64*, i64** %46
%48 = getelementptr inbounds i64, i64* %47, i64 0
%49 = load i64, i64* %48
%50 = inttoptr i64 %49 to i32*
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%53 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %52, i32 0, i32 0
store i32 %51, i32* %53
%54 = load i32, i32* %8
%55 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%56 = call i32 @connect(i32 %54, %struct.sockaddr* %55, i32 12)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %62
58: ; preds = %39
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%60 = load i32, i32* %8
%61 = call i32 @close(i32 %60)
store i32 -4, i32* %3
br label %85
62: ; preds = %39
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%65 = call i32 @memset(i8* %64, i32 0, i32 1024)
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 3
%69 = load i8*, i8** %68
%70 = call i32 @sprintf(i8* %66, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = load i32, i32* %8
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%74 = call i32 @strlen(i8* %73)
%75 = call i32 @send(i32 %71, i8* %72, i32 %74, i32 0)
store i32 %75, i32* %11
%76 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%77 = call i32 @memset(i8* %76, i32 0, i32 4096)
%78 = load i32, i32* %8
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%80 = call i32 @recv(i32 %78, i8* %79, i32 4096, i32 0)
store i32 %80, i32* %13
%81 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %81)
%83 = load i32, i32* %8
%84 = call i32 @close(i32 %83)
store i32 0, i32* %3
br label %85
85: ; preds = %62, %58, %37, %25, %16
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [20 x i8] c"GET %s HTTP/1.0\0D\0A\0D\0A\00"
@str = [17 x i8] c"connect success.\00"
@str.7 = [15 x i8] c"connect error!\00"
@str.8 = [14 x i8] c"socket error!\00"
@str.9 = [21 x i8] c"gethostbyname error!\00"
@str.10 = [28 x i8] c"Not enough input arguments.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca [4096 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 4
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.10, i64 0, i64 0))
br label %58
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 %19
17: ; preds = %12
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
br label %58
19: ; preds = %12
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0))
br label %58
29: ; preds = %19
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %30, i32* %31
%32 = tail call i32 @htons(i32 %22)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%35 = load i64*, i64** %34
%36 = load i64, i64* %35
%37 = inttoptr i64 %36 to i32*
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %38, i32* %39
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = call i32 @connect(i32 %25, %struct.sockaddr* %40, i32 12)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %29
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
%45 = call i32 @close(i32 %25)
br label %58
46: ; preds = %29
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%48 = call i32 @memset(i8* %7, i32 0, i32 1024)
%49 = getelementptr inbounds i8*, i8** %1, i64 3
%50 = load i8*, i8** %49
%51 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %50)
%52 = call i32 @strlen(i8* %7)
%53 = call i32 @send(i32 %25, i8* %7, i32 %52, i32 0)
%54 = call i32 @memset(i8* %8, i32 0, i32 4096)
%55 = call i32 @recv(i32 %25, i8* %8, i32 4096, i32 0)
%56 = call i32 @puts(i8* %8)
%57 = call i32 @close(i32 %25)
br label %58
58: ; preds = %46, %43, %27, %17, %10
%59 = phi i32 [ -1, %10 ], [ -2, %17 ], [ -3, %27 ], [ -4, %43 ], [ 0, %46 ]
ret i32 %59
}