#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 {
  int /*<<< orphan*/ sin_zero;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fe(char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recvCRLF(int, unsigned char *);
int /*<<< orphan*/ sendBytes(int, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strncasecmp(unsigned char *, char *, int);
int main(int argc, char *argv[]) {
  int fdesc;
  struct hostent *host_info;
  struct sockaddr_in targ_addr;
  unsigned char buf[4096];
  if (argc < 2) {
    printf("USAGE %s [fqdn]\n", argv[0]);
    exit(-1);
  }
  if ((host_info = gethostbyname(argv[1])) == NULL) {
    fe("name lookup");
  }
  if ((fdesc = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
    fe("Socket");
  }
  targ_addr.sin_family = AF_INET;
  targ_addr.sin_port = htons(80);
  targ_addr.sin_addr = *((struct in_addr *)(host_info->h_addr));
  memset(&(targ_addr.sin_zero), '\0', 8);
  if (connect(fdesc, (struct sockaddr *)&targ_addr, sizeof(struct sockaddr)) ==
      -1) {
    fe("at connecting");
  }
  sendBytes(fdesc, "HEAD / HTTP/1.0\r\n\r\n");
  while (recvCRLF(fdesc, buf)) {
    if (strncasecmp(buf, "Server:", 7) == 0) {
      printf("%s %s %s\n", argv[1],
             inet_ntoa(*(struct in_addr *)host_info->h_addr), buf + 8);
      exit(0);
    }
  }
  printf("No lines found");
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1202 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1229 <main+0x69>
lea    0xded(%rip),%rdi
call   10a0 <fe@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    125a <main+0x9a>
lea    0xdc8(%rip),%rdi
call   10a0 <fe@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x50,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
jne    12b5 <main+0xf5>
lea    0xd74(%rip),%rdi
call   10a0 <fe@plt>
mov    -0x14(%rbp),%edi
lea    0xd73(%rip),%rsi
call   10d0 <sendBytes@plt>
mov    -0x14(%rbp),%edi
lea    -0x1030(%rbp),%rsi
call   1060 <recvCRLF@plt>
cmp    $0x0,%rax
je     134b <main+0x18b>
lea    -0x1030(%rbp),%rdi
lea    0xd5b(%rip),%rsi
mov    $0x7,%edx
call   1090 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1346 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x1038(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x1038(%rbp),%rsi
mov    %rax,%rdx
lea    -0x1030(%rbp),%rcx
add    $0x8,%rcx
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    12c4 <main+0x104>
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1010,%rsp
mov    %rsi,%r15
cmp    $0x1,%edi
jg     11f2 <main+0x32>
mov    (%r15),%rsi
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x8(%r15),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,%r14
test   %rax,%rax
jne    120f <main+0x4f>
lea    0xe07(%rip),%rdi
call   10a0 <fe@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jne    123c <main+0x7c>
lea    0xde6(%rip),%rdi
call   10a0 <fe@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x50,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    (%r14),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1293 <main+0xd3>
lea    0xd96(%rip),%rdi
call   10a0 <fe@plt>
lea    0xd98(%rip),%rsi
mov    %r12d,%edi
call   10d0 <sendBytes@plt>
lea    0x10(%rsp),%rbx
lea    0xd98(%rip),%rbp
xchg   %ax,%ax
mov    %r12d,%edi
mov    %rbx,%rsi
call   1060 <recvCRLF@plt>
test   %rax,%rax
je     1303 <main+0x143>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x7,%edx
call   1090 <strncasecmp@plt>
test   %rax,%rax
jne    12b0 <main+0xf0>
mov    0x8(%r15),%rbx
mov    (%r14),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
lea    0x18(%rsp),%rcx
lea    0xd5f(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd4e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"USAGE %s [fqdn]\0A\00"
@.str.1 = [12 x i8] c"name lookup\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"Socket\00"
@AF_INET = global i32 0
@.str.3 = [14 x i8] c"at connecting\00"
@.str.4 = [20 x i8] c"HEAD / HTTP/1.0\0D\0A\0D\0A\00"
@.str.5 = [8 x i8] c"Server:\00"
@.str.6 = [10 x i8] c"%s %s %s\0A\00"
@.str.7 = [15 x i8] c"No lines found\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
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** %7
%23 = icmp eq %struct.hostent* %22, null
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @fe(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %18
%27 = load i32, i32* @PF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
store i32 %29, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @fe(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 3
store i32 %34, i32* %35
%36 = call i32 @htons(i32 80)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%39 = load %struct.hostent*, %struct.hostent** %7
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i32 0, i32 0
%41 = load i64, i64* %40
%42 = inttoptr i64 %41 to %struct.in_addr*
%43 = bitcast %struct.in_addr* %38 to i8*
%44 = bitcast %struct.in_addr* %42 to i8*
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%46 = call i32 @memset(i32* %45, i8 signext 0, i32 8)
%47 = load i32, i32* %6
%48 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%49 = call i32 @connect(i32 %47, %struct.sockaddr* %48, i32 4)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %33
%52 = call i32 @fe(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %51, %33
%54 = load i32, i32* %6
%55 = call i32 @sendBytes(i32 %54, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %80, %53
%57 = load i32, i32* %6
%58 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%59 = call i64 @recvCRLF(i32 %57, i8* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %81
61: ; preds = %56
%62 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%63 = call i64 @strncasecmp(i8* %62, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 7)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %80
65: ; preds = %61
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = load %struct.hostent*, %struct.hostent** %7
%70 = getelementptr inbounds %struct.hostent, %struct.hostent* %69, i32 0, i32 0
%71 = load i64, i64* %70
%72 = inttoptr i64 %71 to %struct.in_addr*
%73 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = call i8* @inet_ntoa(i32 %74)
%76 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%77 = getelementptr inbounds i8, i8* %76, i64 8
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %68, i8* %75, i8* %77)
%79 = call i32 @exit(i32 0)
unreachable
80: ; preds = %61
br label %56
81: ; preds = %56
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"USAGE %s [fqdn]\0A\00"
@.str.1 = [12 x i8] c"name lookup\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"Socket\00"
@AF_INET = global i32 0
@.str.3 = [14 x i8] c"at connecting\00"
@.str.4 = [20 x i8] c"HEAD / HTTP/1.0\0D\0A\0D\0A\00"
@.str.5 = [8 x i8] c"Server:\00"
@.str.6 = [10 x i8] c"%s %s %s\0A\00"
@.str.7 = [15 x i8] c"No lines found\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [4096 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 -1)
unreachable
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 @fe(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = load i32, i32* @PF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = tail call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @fe(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %27, i32* %28
%29 = tail call i32 @htons(i32 80)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%32 = load i64, i64* %31
%33 = inttoptr i64 %32 to i32*
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%35 = load i32, i32* %33
store i32 %35, i32* %34
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%37 = call i32 @memset(i32* %36, i8 signext 0, i32 8)
%38 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%39 = call i32 @connect(i32 %22, %struct.sockaddr* %38, i32 4)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %26
%42 = call i32 @fe(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %26
%44 = call i32 @sendBytes(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %48, %43
%46 = call i64 @recvCRLF(i32 %22, i8* %6)
%47 = icmp eq i64 %46, 0
br i1 %47, label %61, label %48
48: ; preds = %45
%49 = call i64 @strncasecmp(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 7)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %45
51: ; preds = %48
%52 = load i8*, i8** %13
%53 = load i64, i64* %31
%54 = inttoptr i64 %53 to %struct.in_addr*
%55 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %54, i64 0, i32 0
%56 = load i32, i32* %55
%57 = call i8* @inet_ntoa(i32 %56)
%58 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 8
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %52, i8* %57, i8* %58)
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %45
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
}