#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 EOF;
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, bytes_received;
  char buf[255], rec[256];
  d_sock = open_socket("en.wikipedia.org", "80");
  sprintf(buf, "GET /wiki/%s http/1.1\r\n", argv[1]);
  say(d_sock, buf);
  say(d_sock, "Host: en.wikipedia.org\r\n\r\n");
  bytes_received = recv(d_sock, rec, 255, 0);
  while (bytes_received) {
    if (bytes_received == EOF)
      error("can't read from server");
    rec[bytes_received] = '\0';
    printf("%s", rec);
    bytes_received = recv(d_sock, rec, 255, 0);
  }
  close(d_sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1040 <open_socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe5f(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
call   1090 <say@plt>
mov    -0x14(%rbp),%edi
lea    0xe59(%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,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1256 <main+0xe6>
mov    -0x18(%rbp),%eax
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%eax
jne    1219 <main+0xa9>
lea    0xe33(%rip),%rdi
call   1070 <error@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rsi
lea    0xe2b(%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,-0x18(%rbp)
jmp    11f1 <main+0x81>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
lea    0xe75(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1040 <open_socket@plt>
mov    %eax,%r12d
mov    0x8(%rbx),%rdx
lea    0xe6f(%rip),%rsi
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1090 <say@plt>
lea    0xe65(%rip),%rsi
mov    %r12d,%edi
call   1090 <say@plt>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     124a <main+0xda>
mov    %eax,%ebp
mov    0x2dfa(%rip),%r13
lea    0xe52(%rip),%r14
lea    0xe62(%rip),%r15
mov    %rsp,%rbx
jmp    123a <main+0xca>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
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
test   %eax,%eax
je     124a <main+0xda>
cmp    0x0(%r13),%ebp
jne    1210 <main+0xa0>
mov    %r14,%rdi
call   1070 <error@plt>
jmp    1210 <main+0xa0>
mov    %r12d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"en.wikipedia.org\00"
@.str.1 = [3 x i8] c"80\00"
@.str.2 = [24 x i8] c"GET /wiki/%s http/1.1\0D\0A\00"
@.str.3 = [27 x i8] c"Host: en.wikipedia.org\0D\0A\0D\0A\00"
@EOF = global i32 0
@.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 i32
%8 = alloca [255 x i8]
%9 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @open_socket(i8* getelementptr inbounds ([17 x i8], [17 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]* %8, 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 ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* %6
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %8, 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 ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* %6
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%23 = call i32 @recv(i32 %21, i8* %22, i32 255, i32 0)
store i32 %23, i32* %7
br label %24
24: ; preds = %33, %2
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %24
%28 = load i32, i32* %7
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %35
store i8 0, i8* %36
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%38 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %6
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%41 = call i32 @recv(i32 %39, i8* %40, i32 255, i32 0)
store i32 %41, i32* %7
br label %24
42: ; preds = %24
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"en.wikipedia.org\00"
@.str.1 = [3 x i8] c"80\00"
@.str.2 = [24 x i8] c"GET /wiki/%s http/1.1\0D\0A\00"
@.str.3 = [27 x i8] c"Host: en.wikipedia.org\0D\0A\0D\0A\00"
@EOF = global i32 0
@.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 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @open_socket(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = call i32 @say(i32 %7, i8* %5)
%12 = call i32 @say(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @recv(i32 %7, i8* %6, i32 255, i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %2, %21
%16 = phi i32 [ %25, %21 ], [ %13, %2 ]
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = sext i32 %16 to i64
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %22
store i8 0, i8* %23
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%25 = call i32 @recv(i32 %7, i8* %6, i32 255, i32 0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %15
27: ; preds = %21, %2
%28 = call i32 @close(i32 %7)
ret i32 0
}