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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ i_connect(int, char *, int);
int i_socket();
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
void connect_get() {
  int cnt, m, size = 500;
  char buf[500];
  char req[32] = "    GET / HTTP/1.1 \r\n";
  int sock = i_socket();
  char *host = "localhost";
  int port = 1234;
  if (i_connect(sock, host, port) < 0) {
    printf("Connection refused\n");
    exit(1);
  }
  send(sock, req, sizeof(req), 0);
  m = 0;
  while ((cnt = read(sock, buf, size)) > 0) {
    m += cnt;
    if (m >= 12)
      break;
  }
  close(sock);
}


x86 assembly (clang, -O0):
<connect_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x1f4,-0xc(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x220(%rbp)
mov    0xe71(%rip),%rax
mov    %rax,-0x218(%rbp)
mov    0xe6b(%rip),%rax
mov    %rax,-0x210(%rbp)
mov    0xe65(%rip),%rax
mov    %rax,-0x208(%rbp)
mov    $0x0,%al
call   1080 <i_socket@plt>
mov    %eax,-0x224(%rbp)
lea    0xe52(%rip),%rax
mov    %rax,-0x230(%rbp)
movl   $0x4d2,-0x234(%rbp)
mov    -0x224(%rbp),%edi
mov    -0x230(%rbp),%rsi
mov    -0x234(%rbp),%edx
call   1030 <i_connect@plt>
cmp    $0x0,%rax
jge    1217 <connect_get+0xa7>
lea    0xe22(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x224(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x224(%rbp),%edi
lea    -0x200(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jle    1275 <connect_get+0x105>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xc,-0x8(%rbp)
jl     1270 <connect_get+0x100>
jmp    1275 <connect_get+0x105>
jmp    1237 <connect_get+0xc7>
mov    -0x224(%rbp),%edi
call   1060 <close@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_get>:
push   %rbp
push   %r14
push   %rbx
sub    $0x220,%rsp
movaps 0xe8e(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe72(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <i_socket@plt>
mov    %eax,%ebx
lea    0xe7c(%rip),%rsi
mov    %eax,%edi
mov    $0x4d2,%edx
call   1030 <i_connect@plt>
test   %rax,%rax
js     11fd <connect_get+0x8d>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0x20(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1f4,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    11ea <connect_get+0x7a>
add    %eax,%ebp
cmp    $0xc,%ebp
jl     11d0 <connect_get+0x60>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x220,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.connect_get.req = [32 x i8] c" GET / HTTP/1.1 \0D\0A\00\00\00\00\00\00\00\00\00\00\00"
@.str = [10 x i8] c"localhost\00"
@.str.1 = [20 x i8] c"Connection refused\0A\00"
define void @connect_get() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [500 x i8]
%5 = alloca [32 x i8]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 500, i32* %3
%9 = bitcast [32 x i8]* %5 to i8*
%10 = call i32 (...) @i_socket()
store i32 %10, i32* %6
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 1234, i32* %8
%11 = load i32, i32* %6
%12 = load i8*, i8** %7
%13 = load i32, i32* %8
%14 = call i64 @i_connect(i32 %11, i8* %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = load i32, i32* %6
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%22 = call i32 @send(i32 %20, i8* %21, i32 32, i32 0)
store i32 0, i32* %2
br label %23
23: ; preds = %36, %19
%24 = load i32, i32* %6
%25 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%26 = load i32, i32* %3
%27 = call i32 @read(i32 %24, i8* %25, i32 %26)
store i32 %27, i32* %1
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = add nsw i32 %31, %30
store i32 %32, i32* %2
%33 = load i32, i32* %2
%34 = icmp sge i32 %33, 12
br i1 %34, label %35, label %36
35: ; preds = %29
br label %37
36: ; preds = %29
br label %23
37: ; preds = %35, %23
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
ret void
}

LLVM IR (-O2):
@__const.connect_get.req = [32 x i8] c" GET / HTTP/1.1 \0D\0A\00\00\00\00\00\00\00\00\00\00\00"
@.str = [10 x i8] c"localhost\00"
@str = [19 x i8] c"Connection refused\00"
define void @connect_get() {
%1 = alloca [500 x i8]
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [500 x i8], [500 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @i_socket()
%6 = tail call i64 @i_connect(i32 %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 1234)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32 @send(i32 %5, i8* %4, i32 32, i32 0)
br label %13
13: ; preds = %13, %11
%14 = phi i32 [ 0, %11 ], [ %17, %13 ]
%15 = call i32 @read(i32 %5, i8* %3, i32 500)
%16 = icmp slt i32 %15, 1
%17 = add nsw i32 %15, %14
%18 = icmp sgt i32 %17, 11
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %13
20: ; preds = %13
%21 = call i32 @close(i32 %5)
ret void
}