#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int open_socket(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ say(int, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int argc, char *argv[]) {
  int d_sock;
  d_sock = open_socket("www.infoq.com", "80");
  char buf[255];
  sprintf(buf, "GET / HTTP/1.1\r\n", argv[1]);
  say(d_sock, buf);
  say(d_sock, "Host: www.infoq.com\r\n\r\n");
  char rec[256];
  int bytesRcvd = recv(d_sock, rec, 255, 0);
  while (bytesRcvd) {
    if (bytesRcvd == -1)
      error("Can't read from server");
    rec[bytesRcvd] = '\0';
    printf("%s", rec);
    bytesRcvd = recv(d_sock, rec, 255, 0);
  }
  close(d_sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1040 <open_socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe5c(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
call   1090 <say@plt>
mov    -0x14(%rbp),%edi
lea    0xe4f(%rip),%rsi
call   1090 <say@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x0,-0x224(%rbp)
je     125d <main+0xed>
cmpl   $0xffffffff,-0x224(%rbp)
jne    121a <main+0xaa>
lea    0xe25(%rip),%rdi
call   1070 <error@plt>
movslq -0x224(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x224(%rbp)
jmp    11f4 <main+0x84>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbx
lea    0xe77(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <open_socket@plt>
mov    %eax,%r12d
mov    0x8(%rbx),%rdx
lea    0xe6e(%rip),%rsi
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1090 <say@plt>
lea    0xe5d(%rip),%rsi
mov    %r12d,%edi
call   1090 <say@plt>
mov    %rsp,%rbx
lea    0xe63(%rip),%r14
lea    0xe73(%rip),%r15
jmp    11fa <main+0x8a>
mov    %r14,%rdi
call   1070 <error@plt>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11e0 <main+0x70>
test   %ebp,%ebp
jne    11e8 <main+0x78>
mov    %r12d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"www.infoq.com\00"
@.str.1 = [3 x i8] c"80\00"
@.str.2 = [17 x i8] c"GET / HTTP/1.1\0D\0A\00"
@.str.3 = [24 x i8] c"Host: www.infoq.com\0D\0A\0D\0A\00"
@.str.4 = [23 x i8] c"Can't read from server\00"
@.str.5 = [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 [255 x i8]
%8 = alloca [256 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @open_socket(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %10, i32* %6
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* %6
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%18 = call i32 @say(i32 %16, i8* %17)
%19 = load i32, i32* %6
%20 = call i32 @say(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* %6
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%23 = call i32 @recv(i32 %21, i8* %22, i32 255, i32 0)
store i32 %23, i32* %9
br label %24
24: ; preds = %32, %2
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %34
store i8 0, i8* %35
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %6
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%40 = call i32 @recv(i32 %38, i8* %39, i32 255, i32 0)
store i32 %40, i32* %9
br label %24
41: ; preds = %24
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"www.infoq.com\00"
@.str.1 = [3 x i8] c"80\00"
@.str.2 = [17 x i8] c"GET / HTTP/1.1\0D\0A\00"
@.str.3 = [24 x i8] c"Host: www.infoq.com\0D\0A\0D\0A\00"
@.str.4 = [23 x i8] c"Can't read from server\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = alloca [256 x i8]
%5 = tail call i32 @open_socket(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = call i32 @say(i32 %5, i8* %6)
%11 = call i32 @say(i32 %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
br label %13
13: ; preds = %17, %2
%14 = call i32 @recv(i32 %5, i8* %12, i32 255, i32 0)
switch i32 %14, label %17 [
i32 0, label %21
i32 -1, label %15
]
15: ; preds = %13
%16 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %13, %15
%18 = sext i32 %14 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %12)
br label %13
21: ; preds = %13
%22 = call i32 @close(i32 %5)
ret i32 0
}