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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd, port, n;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  char buffer[256];
  FILE *fp;
  if (argc < 5) {
    fprintf(stderr, "usage: %s [method] [host] [port] [path]\n", argv[0]);
    fprintf(stderr, "method - GET or HEAD [GET]\n");
    fprintf(stderr, "host - ip [127.0.0.1]\n");
    fprintf(stderr, "port - port number [9091]\n");
    fprintf(stderr, "path - requested file path [/index.html]\n");
    exit(0);
  }
  if (strcmp(argv[1], "GET") != 0 && strcmp(argv[1], "HEAD") != 0) {
    fprintf(stderr, "ERROR, method not supported!\n");
    exit(0);
  }
  port = atoi(argv[3]);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    fprintf(stderr, "ERROR opening socket\n");
    exit(0);
  }
  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(port);
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    fprintf(stderr, "ERROR connecting\n");
    exit(0);
  }
  bzero(buffer, 256);
  strcpy(buffer, argv[1]);
  strcat(buffer, " ");
  strcat(buffer, argv[4]);
  strcat(buffer, " ");
  strcat(buffer, "HTTP/1.0");
  n = write(sockfd, buffer, strlen(buffer));
  if (n < 0) {
    fprintf(stderr, "ERROR writing to socket\n");
    exit(0);
  }
  bzero(buffer, 256);
  int i = 0;
  char buffer2[256];
  while (read(sockfd, buffer, 1)) {
    if (i < 4) {
      if (strcmp(buffer, "\n") != 0) {
        strcat(buffer2, buffer);
      } else {
        i++;
        strcpy(buffer2, "");
      }
    } else {
      printf("%s", buffer);
    }
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    12b4 <main+0xa4>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdde(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     130e <main+0xfe>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc4(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     130e <main+0xfe>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
mov    0x2ca2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1362 <main+0x152>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
lea    0xd74(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    139c <main+0x18c>
mov    0x2c53(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2c37(%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
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
cmp    $0x0,%rax
jge    1415 <main+0x205>
mov    0x2bda(%rip),%rax
mov    (%rax),%edi
lea    0xcec(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x130(%rbp),%rdi
lea    0xcbd(%rip),%rsi
call   1100 <strcat@plt>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
call   1100 <strcat@plt>
lea    -0x130(%rbp),%rdi
lea    0xc96(%rip),%rsi
call   1100 <strcat@plt>
lea    -0x130(%rbp),%rdi
lea    0xc85(%rip),%rsi
call   1100 <strcat@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24c(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x248(%rbp)
lea    -0x130(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x24c(%rbp),%edi
mov    -0x248(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    14e9 <main+0x2d9>
mov    0x2b06(%rip),%rax
mov    (%rax),%edi
lea    0xc35(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
movl   $0x0,-0x13c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x0,%rax
je     15a3 <main+0x393>
cmpl   $0x4,-0x13c(%rbp)
jge    158b <main+0x37b>
lea    -0x130(%rbp),%rdi
lea    0xb89(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1564 <main+0x354>
lea    -0x240(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1100 <strcat@plt>
jmp    1586 <main+0x376>
mov    -0x13c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13c(%rbp)
lea    -0x240(%rbp),%rdi
lea    0xb46(%rip),%rsi
call   1030 <strcpy@plt>
jmp    159e <main+0x38e>
lea    -0x130(%rbp),%rsi
lea    0xb90(%rip),%rdi
call   1070 <printf@plt>
jmp    1504 <main+0x2f4>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r14
cmp    $0x4,%edi
jle    1422 <main+0x212>
mov    0x8(%r14),%rdi
lea    0xe69(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     125b <main+0x4b>
mov    0x8(%r14),%rdi
lea    0xe58(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    14bf <main+0x2af>
mov    0x18(%r14),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r15d
mov    0x2d7a(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     1477 <main+0x267>
mov    %eax,%ebp
mov    0x10(%r14),%rdi
call   10b0 <gethostbyname@plt>
test   %rax,%rax
je     1489 <main+0x279>
mov    %rax,%rbx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rsi
lea    0x4(%rsp),%rdi
mov    (%rbx),%edx
call   10d0 <memmove@plt>
mov    %r15d,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
test   %rax,%rax
js     149b <main+0x28b>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xdf4(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1100 <strcat@plt>
mov    0x20(%r14),%rsi
mov    %rbx,%rdi
call   1100 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1100 <strcat@plt>
lea    0xdcd(%rip),%rsi
mov    %rbx,%rdi
call   1100 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
js     14ad <main+0x29d>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %rax,%rax
je     1407 <main+0x1f7>
xor    %r15d,%r15d
lea    0xd34(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0x110(%rsp),%r12
lea    0xd83(%rip),%r13
jmp    13cf <main+0x1bf>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %rax,%rax
je     1407 <main+0x1f7>
cmp    $0x3,%r15d
jg     13b0 <main+0x1a0>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     13f2 <main+0x1e2>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1100 <strcat@plt>
jmp    13bb <main+0x1ab>
add    $0x1,%r15d
mov    %r12,%rdi
lea    0xcc7(%rip),%rsi
call   1030 <strcpy@plt>
jmp    13bb <main+0x1ab>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2baf(%rip),%rbx
mov    (%rbx),%edi
mov    (%r14),%rdx
lea    0xbcb(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xbe4(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xbf0(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xbf7(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xc02(%rip),%rsi
jmp    14cf <main+0x2bf>
mov    0x2b5a(%rip),%rax
mov    (%rax),%edi
lea    0xc41(%rip),%rsi
jmp    14cf <main+0x2bf>
mov    0x2b48(%rip),%rax
mov    (%rax),%edi
lea    0xc45(%rip),%rsi
jmp    14cf <main+0x2bf>
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
lea    0xc48(%rip),%rsi
jmp    14cf <main+0x2bf>
mov    0x2b24(%rip),%rax
mov    (%rax),%edi
lea    0xc53(%rip),%rsi
jmp    14cf <main+0x2bf>
mov    0x2b12(%rip),%rax
mov    (%rax),%edi
lea    0xbdb(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1110 <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 = [41 x i8] c"usage: %s [method] [host] [port] [path]\0A\00"
@.str.1 = [28 x i8] c"method - GET or HEAD [GET]\0A\00"
@.str.2 = [23 x i8] c"host - ip [127.0.0.1]\0A\00"
@.str.3 = [27 x i8] c"port - port number [9091]\0A\00"
@.str.4 = [42 x i8] c"path - requested file path [/index.html]\0A\00"
@.str.5 = [4 x i8] c"GET\00"
@.str.6 = [5 x i8] c"HEAD\00"
@.str.7 = [30 x i8] c"ERROR, method not supported!\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.8 = [22 x i8] c"ERROR opening socket\0A\00"
@.str.9 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.10 = [18 x i8] c"ERROR connecting\0A\00"
@.str.11 = [2 x i8] c" \00"
@.str.12 = [9 x i8] c"HTTP/1.0\00"
@.str.13 = [25 x i8] c"ERROR writing to socket\0A\00"
@.str.14 = [2 x i8] c"\0A\00"
@.str.15 = [1 x i8] zeroinitializer
@.str.16 = [3 x i8] c"%s\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 [256 x i8]
%12 = alloca i32*
%13 = alloca i32
%14 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 5
br i1 %16, label %17, label %32
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %2
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %32
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %38, %32
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call i32 @atoi(i8* %51)
store i32 %52, i32* %7
%53 = load i32, i32* @AF_INET
%54 = load i32, i32* @SOCK_STREAM
%55 = call i32 @socket(i32 %53, i32 %54, i32 0)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %48
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%61 = call i32 @exit(i32 0)
unreachable
62: ; preds = %48
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = call %struct.hostent* @gethostbyname(i8* %65)
store %struct.hostent* %66, %struct.hostent** %10
%67 = load %struct.hostent*, %struct.hostent** %10
%68 = icmp eq %struct.hostent* %67, null
br i1 %68, label %69, label %73
69: ; preds = %62
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%72 = call i32 @exit(i32 0)
unreachable
73: ; preds = %62
%74 = bitcast %struct.sockaddr_in* %9 to i8*
%75 = call i32 @bzero(i8* %74, i32 12)
%76 = load i32, i32* @AF_INET
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %76, i32* %77
%78 = load %struct.hostent*, %struct.hostent** %10
%79 = getelementptr inbounds %struct.hostent, %struct.hostent* %78, i32 0, i32 1
%80 = load i64, i64* %79
%81 = inttoptr i64 %80 to i8*
%82 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%83 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %82, i32 0, i32 0
%84 = bitcast i32* %83 to i8*
%85 = load %struct.hostent*, %struct.hostent** %10
%86 = getelementptr inbounds %struct.hostent, %struct.hostent* %85, i32 0, i32 0
%87 = load i32, i32* %86
%88 = call i32 @bcopy(i8* %81, i8* %84, i32 %87)
%89 = load i32, i32* %7
%90 = call i32 @htons(i32 %89)
%91 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %90, i32* %91
%92 = load i32, i32* %6
%93 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%94 = call i64 @connect(i32 %92, %struct.sockaddr* %93, i32 12)
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %73
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
%99 = call i32 @exit(i32 0)
unreachable
100: ; preds = %73
%101 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%102 = call i32 @bzero(i8* %101, i32 256)
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%104 = load i8**, i8*** %5
%105 = getelementptr inbounds i8*, i8** %104, i64 1
%106 = load i8*, i8** %105
%107 = call i32 @strcpy(i8* %103, i8* %106)
%108 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%109 = call i32 @strcat(i8* %108, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%111 = load i8**, i8*** %5
%112 = getelementptr inbounds i8*, i8** %111, i64 4
%113 = load i8*, i8** %112
%114 = call i32 @strcat(i8* %110, i8* %113)
%115 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%116 = call i32 @strcat(i8* %115, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%117 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%118 = call i32 @strcat(i8* %117, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%119 = load i32, i32* %6
%120 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%121 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%122 = call i32 @strlen(i8* %121)
%123 = call i32 @write(i32 %119, i8* %120, i32 %122)
store i32 %123, i32* %8
%124 = load i32, i32* %8
%125 = icmp slt i32 %124, 0
br i1 %125, label %126, label %130
126: ; preds = %100
%127 = load i32, i32* @stderr
%128 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%129 = call i32 @exit(i32 0)
unreachable
130: ; preds = %100
%131 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%132 = call i32 @bzero(i8* %131, i32 256)
store i32 0, i32* %13
br label %133
133: ; preds = %158, %130
%134 = load i32, i32* %6
%135 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%136 = call i64 @read(i32 %134, i8* %135, i32 1)
%137 = icmp ne i64 %136, 0
br i1 %137, label %138, label %159
138: ; preds = %133
%139 = load i32, i32* %13
%140 = icmp slt i32 %139, 4
br i1 %140, label %141, label %155
141: ; preds = %138
%142 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%143 = call i64 @strcmp(i8* %142, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
%144 = icmp ne i64 %143, 0
br i1 %144, label %145, label %149
145: ; preds = %141
%146 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%147 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%148 = call i32 @strcat(i8* %146, i8* %147)
br label %154
149: ; preds = %141
%150 = load i32, i32* %13
%151 = add nsw i32 %150, 1
store i32 %151, i32* %13
%152 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%153 = call i32 @strcpy(i8* %152, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.15, i64 0, i64 0))
br label %154
154: ; preds = %149, %145
br label %158
155: ; preds = %138
%156 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%157 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0), i8* %156)
br label %158
158: ; preds = %155, %154
br label %133
159: ; preds = %133
%160 = load i32, i32* %6
%161 = call i32 @close(i32 %160)
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 = [41 x i8] c"usage: %s [method] [host] [port] [path]\0A\00"
@.str.1 = [28 x i8] c"method - GET or HEAD [GET]\0A\00"
@.str.2 = [23 x i8] c"host - ip [127.0.0.1]\0A\00"
@.str.3 = [27 x i8] c"port - port number [9091]\0A\00"
@.str.4 = [42 x i8] c"path - requested file path [/index.html]\0A\00"
@.str.5 = [4 x i8] c"GET\00"
@.str.6 = [5 x i8] c"HEAD\00"
@.str.7 = [30 x i8] c"ERROR, method not supported!\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.8 = [22 x i8] c"ERROR opening socket\0A\00"
@.str.9 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.10 = [18 x i8] c"ERROR connecting\0A\00"
@.str.11 = [2 x i8] c" \00"
@.str.12 = [9 x i8] c"HTTP/1.0\00"
@.str.13 = [25 x i8] c"ERROR writing to socket\0A\00"
@.str.14 = [2 x i8] c"\0A\00"
@.str.15 = [1 x i8] zeroinitializer
@.str.16 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = icmp slt i32 %0, 5
br i1 %8, label %9, label %22
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 ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %22
%28 = load i8*, i8** %23
%29 = tail call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%34 = tail call i32 @exit(i32 0)
unreachable
35: ; preds = %27, %22
%36 = getelementptr inbounds i8*, i8** %1, i64 3
%37 = load i8*, i8** %36
%38 = tail call i32 @atoi(i8* %37)
%39 = load i32, i32* @AF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = tail call i32 @socket(i32 %39, i32 %40, i32 0)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%46 = tail call i32 @exit(i32 0)
unreachable
47: ; preds = %35
%48 = getelementptr inbounds i8*, i8** %1, i64 2
%49 = load i8*, i8** %48
%50 = tail call %struct.hostent* @gethostbyname(i8* %49)
%51 = icmp eq %struct.hostent* %50, null
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%55 = tail call i32 @exit(i32 0)
unreachable
56: ; preds = %47
%57 = call i32 @bzero(i8* %6, i32 12)
%58 = load i32, i32* @AF_INET
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %58, i32* %59
%60 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i64 0, i32 1
%61 = load i64, i64* %60
%62 = inttoptr i64 %61 to i8*
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%64 = bitcast i32* %63 to i8*
%65 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i64 0, i32 0
%66 = load i32, i32* %65
%67 = tail call i32 @htons(i32 %38)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %67, i32* %68
%69 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%70 = call i64 @connect(i32 %41, %struct.sockaddr* %69, i32 12)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %56
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
%75 = call i32 @exit(i32 0)
unreachable
76: ; preds = %56
%77 = call i32 @bzero(i8* %7, i32 256)
%78 = load i8*, i8** %23
%79 = call i32 @strcpy(i8* %7, i8* %78)
%80 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%81 = getelementptr inbounds i8*, i8** %1, i64 4
%82 = load i8*, i8** %81
%83 = call i32 @strcat(i8* %7, i8* %82)
%84 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%85 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%86 = call i32 @strlen(i8* %7)
%87 = call i32 @write(i32 %41, i8* %7, i32 %86)
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %76
%90 = load i32, i32* @stderr
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%92 = call i32 @exit(i32 0)
unreachable
93: ; preds = %76
%94 = call i32 @bzero(i8* %7, i32 256)
%95 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%96 = call i64 @read(i32 %41, i8* %7, i32 1)
%97 = icmp eq i64 %96, 0
br i1 %97, label %115, label %98
98: ; preds = %93, %111
%99 = phi i32 [ %112, %111 ], [ 0, %93 ]
%100 = icmp slt i32 %99, 4
br i1 %100, label %101, label %109
101: ; preds = %98
%102 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
%103 = icmp eq i64 %102, 0
br i1 %103, label %106, label %104
104: ; preds = %101
%105 = call i32 @strcat(i8* %95, i8* %7)
br label %111
106: ; preds = %101
%107 = add nsw i32 %99, 1
%108 = call i32 @strcpy(i8* %95, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.15, i64 0, i64 0))
br label %111
109: ; preds = %98
%110 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0), i8* %7)
br label %111
111: ; preds = %104, %106, %109
%112 = phi i32 [ %99, %104 ], [ %107, %106 ], [ %99, %109 ]
%113 = call i64 @read(i32 %41, i8* %7, i32 1)
%114 = icmp eq i64 %113, 0
br i1 %114, label %115, label %98
115: ; preds = %111, %93
%116 = call i32 @close(i32 %41)
ret i32 0
}