#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 */
typedef int /*<<< orphan*/ inbuf;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ close(int);
int devopen(char *, char *);
int dup(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int write(int, char *, int);
int main(int argc, char **argv) {
  int ofd;
  int ifd;
  int n;
  int nread;
  int wrote;
  char inbuf[BUFSIZ];
  char outbuf[] = "GET index.html HTTP/1.0\r\n\r\n";
  char sockname[BUFSIZ];
  strcpy(sockname, "/inet/tcp/0/www.yahoo.com/80");
  ofd = devopen(sockname, "rw");
  if (ofd < 0) {
    perror("devopen");
    exit(1);
  }
  if ((ifd = dup(ofd)) < 0) {
    perror("dup");
    exit(1);
  }
  n = strlen(outbuf);
  if ((wrote = write(ofd, outbuf, n)) != n) {
    perror("write");
    exit(1);
  }
  while ((nread = read(ifd, inbuf, sizeof(inbuf))) > 0) {
    write(1, inbuf, nread);
  }
  close(ifd);
  close(ofd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x80(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x78(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x38(%rbp)
movups 0xe2c(%rip),%xmm0
movups %xmm0,-0x54(%rbp)
movaps 0xe15(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x68(%rbp)
lea    0xe08(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x70(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1090 <devopen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    124c <main+0xbc>
lea    0xdff(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1060 <dup@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1276 <main+0xe6>
lea    0xddd(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x24(%rbp)
cmp    -0x1c(%rbp),%eax
je     12b3 <main+0x123>
lea    0xda4(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    12b8 <main+0x128>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rax
mov    -0x18(%rbp),%edi
mov    %eax,%edx
call   1080 <read@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jle    12ec <main+0x15c>
mov    -0x78(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
jmp    12b8 <main+0x128>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e38(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movups 0xe49(%rip),%xmm0
movups %xmm0,-0x44(%rbp)
movaps 0xe32(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe3a(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xe48(%rip),%rsi
mov    %r15,%rdi
call   1090 <devopen@plt>
test   %eax,%eax
js     1274 <main+0xe4>
mov    %eax,%r15d
mov    %eax,%edi
call   1060 <dup@plt>
test   %eax,%eax
js     127d <main+0xed>
mov    %eax,%r12d
lea    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %r15d,%edi
lea    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    %r13d,%eax
jne    1286 <main+0xf6>
nopl   (%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    1253 <main+0xc3>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    1230 <main+0xa0>
mov    %r12d,%edi
call   1070 <close@plt>
mov    %r15d,%edi
call   1070 <close@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc1(%rip),%rdi
jmp    128d <main+0xfd>
lea    0xdc0(%rip),%rdi
jmp    128d <main+0xfd>
lea    0xdbb(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@__const.main.outbuf = [28 x i8] c"GET index.html HTTP/1.0\0D\0A\0D\0A\00"
@.str = [29 x i8] c"/inet/tcp/0/www.yahoo.com/80\00"
@.str.1 = [3 x i8] c"rw\00"
@.str.2 = [8 x i8] c"devopen\00"
@.str.3 = [4 x i8] c"dup\00"
@.str.4 = [6 x i8] c"write\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 i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca [28 x i8]
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @BUFSIZ
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %11
%18 = alloca i8, i64 %16
store i64 %16, i64* %12
%19 = bitcast [28 x i8]* %13 to i8*
%20 = load i32, i32* @BUFSIZ
%21 = zext i32 %20 to i64
%22 = alloca i8, i64 %21
store i64 %21, i64* %14
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @devopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2
%31 = load i32, i32* %6
%32 = call i32 @dup(i32 %31)
store i32 %32, i32* %7
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30
%38 = getelementptr inbounds [28 x i8], [28 x i8]* %13, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
store i32 %39, i32* %8
%40 = load i32, i32* %6
%41 = getelementptr inbounds [28 x i8], [28 x i8]* %13, i64 0, i64 0
%42 = load i32, i32* %8
%43 = call i32 @write(i32 %40, i8* %41, i32 %42)
store i32 %43, i32* %10
%44 = load i32, i32* %8
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %37
%47 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %37
br label %50
50: ; preds = %55, %49
%51 = load i32, i32* %7
%52 = trunc i64 %16 to i32
%53 = call i32 @read(i32 %51, i8* %18, i32 %52)
store i32 %53, i32* %9
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = load i32, i32* %9
%57 = call i32 @write(i32 1, i8* %18, i32 %56)
br label %50
58: ; preds = %50
%59 = load i32, i32* %7
%60 = call i32 @close(i32 %59)
%61 = load i32, i32* %6
%62 = call i32 @close(i32 %61)
store i32 0, i32* %3
%63 = load i8*, i8** %11
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@__const.main.outbuf = [28 x i8] c"GET index.html HTTP/1.0\0D\0A\0D\0A\00"
@.str = [29 x i8] c"/inet/tcp/0/www.yahoo.com/80\00"
@.str.1 = [3 x i8] c"rw\00"
@.str.2 = [8 x i8] c"devopen\00"
@.str.3 = [4 x i8] c"dup\00"
@.str.4 = [6 x i8] c"write\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [28 x i8]
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = getelementptr inbounds [28 x i8], [28 x i8]* %3, i64 0, i64 0
%8 = alloca i8, i64 %5
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @devopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i32 @dup(i32 %10)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = call i32 @strlen(i8* %7)
%23 = call i32 @write(i32 %10, i8* %7, i32 %22)
%24 = icmp eq i32 %23, %22
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @read(i32 %16, i8* %6, i32 %4)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %31, label %36
28: ; preds = %21
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25, %31
%32 = phi i32 [ %34, %31 ], [ %26, %25 ]
%33 = call i32 @write(i32 1, i8* %6, i32 %32)
%34 = call i32 @read(i32 %16, i8* %6, i32 %4)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %31, label %36
36: ; preds = %31, %25
%37 = call i32 @close(i32 %16)
%38 = call i32 @close(i32 %10)
ret i32 0
}