#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[]) {
  if (!argv[1])
    argv[1] = "O'Reilly_Media";
  printf("argv[1] = %s\n", argv[1]);
  int d_sock = open_socket("en.wikipedia.org", "80");
  char buf[255];
  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");
  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("rec %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)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11a7 <main+0x37>
mov    -0x10(%rbp),%rax
lea    0xe5d(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
lea    0xe5b(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1040 <open_socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe4a(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
call   1090 <say@plt>
mov    -0x14(%rbp),%edi
lea    0xe44(%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     128f <main+0x11f>
cmpl   $0xffffffff,-0x224(%rbp)
jne    124c <main+0xdc>
lea    0xe1d(%rip),%rdi
call   1070 <error@plt>
movslq -0x224(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rsi
lea    0xe12(%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    1226 <main+0xb6>
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
mov    0x8(%rsi),%rsi
test   %rsi,%rsi
jne    1196 <main+0x26>
lea    0xe6e(%rip),%rsi
mov    %rsi,0x8(%rbx)
lea    0xe72(%rip),%rdi
call   1050 <printf@plt>
lea    0xe74(%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    0xe64(%rip),%rsi
mov    %r12d,%edi
call   1090 <say@plt>
mov    %rsp,%rbx
lea    0xe6d(%rip),%r14
lea    0xe7d(%rip),%r15
jmp    121a <main+0xaa>
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     1200 <main+0x90>
test   %ebp,%ebp
jne    1208 <main+0x98>
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 = [15 x i8] c"O'Reilly_Media\00"
@.str.1 = [14 x i8] c"argv[1] = %s\0A\00"
@.str.2 = [17 x i8] c"en.wikipedia.org\00"
@.str.3 = [3 x i8] c"80\00"
@.str.4 = [24 x i8] c"GET /wiki/%s http/1.1\0D\0A\00"
@.str.5 = [27 x i8] c"Host: en.wikipedia.org\0D\0A\0D\0A\00"
@.str.6 = [23 x i8] c"Can't read from server\00"
@.str.7 = [7 x i8] c"rec %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 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %16
br label %17
17: ; preds = %14, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i32 @open_socket(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 %22, i32* %6
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i32, i32* %6
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%30 = call i32 @say(i32 %28, i8* %29)
%31 = load i32, i32* %6
%32 = call i32 @say(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32, i32* %6
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%35 = call i32 @recv(i32 %33, i8* %34, i32 255, i32 0)
store i32 %35, i32* %9
br label %36
36: ; preds = %44, %17
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %53
39: ; preds = %36
%40 = load i32, i32* %9
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %46
store i8 0, i8* %47
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %48)
%50 = load i32, i32* %6
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%52 = call i32 @recv(i32 %50, i8* %51, i32 255, i32 0)
store i32 %52, i32* %9
br label %36
53: ; preds = %36
%54 = load i32, i32* %6
%55 = call i32 @close(i32 %54)
ret i32 0
}

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