#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 send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strlen(char *);
int http_get(int connection, const char *path, const char *host) {
  static char get_command[255];
  sprintf(get_command, "GET /%s HTTP/1.1\r\n", path);
  if (send(connection, get_command, strlen(get_command), 0) == -1) {
    return -1;
  }
  sprintf(get_command, "Host: %s\r\n", host);
  if (send(connection, get_command, strlen(get_command), 0) == -1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<http_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdx
lea    0x2f02(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    0x2ee9(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0x2ed8(%rip),%rsi
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    1194 <http_get+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <http_get+0xbc>
mov    -0x18(%rbp),%rdx
lea    0x2eb1(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    0x2e98(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0x2e87(%rip),%rsi
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    11e5 <http_get+0xb5>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <http_get+0xbc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_get>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rdx
mov    %edi,%ebp
lea    0x2f0d(%rip),%rbx
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     11aa <http_get+0x7a>
lea    0x2edc(%rip),%rbx
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
neg    %eax
jmp    11af <http_get+0x7f>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@http_get.get_command = internal global [255 x i8] zeroinitializer
@.str = [19 x i8] c"GET /%s HTTP/1.1\0D\0A\00"
@.str.1 = [11 x i8] c"Host: %s\0D\0A\00"
define i32 @http_get(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i8*, i8** %6
%9 = call i32 @sprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* %5
%11 = call i32 @strlen(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0))
%12 = call i32 @send(i32 %10, i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0), i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %24
15: ; preds = %3
%16 = load i8*, i8** %7
%17 = call i32 @sprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %5
%19 = call i32 @strlen(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0))
%20 = call i32 @send(i32 %18, i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0), i32 %19, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 -1, i32* %4
br label %24
23: ; preds = %15
store i32 0, i32* %4
br label %24
24: ; preds = %23, %22, %14
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@http_get.get_command = internal global [255 x i8] zeroinitializer
@.str = [19 x i8] c"GET /%s HTTP/1.1\0D\0A\00"
@.str.1 = [11 x i8] c"Host: %s\0D\0A\00"
define i32 @http_get(i32 %0, i8* %1, i8* %2) {
%4 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0))
%6 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0), i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %14, label %8
8: ; preds = %3
%9 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0))
%11 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([255 x i8], [255 x i8]* @http_get.get_command, i64 0, i64 0), i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %8, %3
%15 = phi i32 [ -1, %3 ], [ %13, %8 ]
ret i32 %15
}