#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 create_inet_stream_socket(char *, char *, int, int /*<<< orphan*/);
int destroy_inet_socket(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int read(int, char *, int);
int shutdown_inet_stream_socket(int, int);
int /*<<< orphan*/ sprintf(char *, char *);
int strlen(char *);
int write(int, char *, int);
int main(void) {
  int sfd, bytes, ret;
  char request[128], buf[32];
  buf[31] = 0;
  ret = sfd = create_inet_stream_socket("lbo.spheniscida.de", "80", 3, 0);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  sprintf(request, "GET / HTTP/1.1\nHost: lbo.spheniscida.de\n\n");
  ret = write(sfd, request, strlen(request));
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = shutdown_inet_stream_socket(sfd, 2);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  while (0 < (bytes = read(sfd, buf, 31)))
    write(1, buf, bytes);
  ret = destroy_inet_socket(sfd);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x91(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1080 <create_inet_stream_socket@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11e4 <main+0x54>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x90(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0x90(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    124c <main+0xbc>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1030 <shutdown_inet_stream_socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1277 <main+0xe7>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    127c <main+0xec>
mov    -0x8(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x1f,%edx
call   1070 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jge    12b8 <main+0x128>
lea    -0xb0(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
jmp    127c <main+0xec>
mov    -0x8(%rbp),%edi
call   1050 <destroy_inet_socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    12de <main+0x14e>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0xa8,%rsp
movb   $0x0,0x1f(%rsp)
lea    0xe6b(%rip),%rdi
lea    0xe77(%rip),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1080 <create_inet_stream_socket@plt>
test   %eax,%eax
js     1259 <main+0xd9>
mov    %eax,%ebp
movups 0xe77(%rip),%xmm0
movups %xmm0,0x3a(%rsp)
movups 0xe61(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movups 0xe45(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
js     1259 <main+0xd9>
mov    %ebp,%edi
mov    $0x2,%esi
call   1030 <shutdown_inet_stream_socket@plt>
test   %eax,%eax
js     1259 <main+0xd9>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x1f,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1242 <main+0xc2>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1f,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     1220 <main+0xa0>
mov    %ebp,%edi
call   1050 <destroy_inet_socket@plt>
test   %eax,%eax
js     1259 <main+0xd9>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"lbo.spheniscida.de\00"
@.str.1 = [3 x i8] c"80\00"
@.str.2 = [42 x i8] c"GET / HTTP/1.1\0AHost: lbo.spheniscida.de\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = alloca [32 x i8]
store i32 0, i32* %1
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 31
store i8 0, i8* %7
%8 = call i32 @create_inet_stream_socket(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 0)
store i32 %8, i32* %2
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i32 0)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%16 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %2
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @write(i32 %17, i8* %18, i32 %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = call i32 @perror(i32 0)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %14
%28 = load i32, i32* %2
%29 = call i32 @shutdown_inet_stream_socket(i32 %28, i32 2)
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i32 0)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27
br label %36
36: ; preds = %41, %35
%37 = load i32, i32* %2
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 31)
store i32 %39, i32* %3
%40 = icmp slt i32 0, %39
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%43 = load i32, i32* %3
%44 = call i32 @write(i32 1, i8* %42, i32 %43)
br label %36
45: ; preds = %36
%46 = load i32, i32* %2
%47 = call i32 @destroy_inet_socket(i32 %46)
store i32 %47, i32* %4
%48 = load i32, i32* %4
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = call i32 @perror(i32 0)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %45
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"lbo.spheniscida.de\00"
@.str.1 = [3 x i8] c"80\00"
@.str.2 = [42 x i8] c"GET / HTTP/1.1\0AHost: lbo.spheniscida.de\0A\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 31
store i8 0, i8* %5
%6 = tail call i32 @create_inet_stream_socket(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @perror(i32 0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32 @strlen(i8* %3)
%13 = call i32 @write(i32 %6, i8* %3, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i32 0)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = call i32 @shutdown_inet_stream_socket(i32 %6, i32 2)
%20 = icmp slt i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = call i32 @read(i32 %6, i8* %4, i32 31)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %27, label %32
24: ; preds = %18
%25 = call i32 @perror(i32 0)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %21, %27
%28 = phi i32 [ %30, %27 ], [ %22, %21 ]
%29 = call i32 @write(i32 1, i8* %4, i32 %28)
%30 = call i32 @read(i32 %6, i8* %4, i32 31)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %27, label %32
32: ; preds = %27, %21
%33 = call i32 @destroy_inet_socket(i32 %6)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = call i32 @perror(i32 0)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %32
ret i32 0
}