#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 */
scalar_t__ __get_squid_info(char *, char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int __read_squid_stat(int port, int index) {
  int i;
  char *options[2] = {"info", "counters"};
  char msg[2][512];
  for (i = 0; i < 2; i++) {
    sprintf(msg[i],
            "GET cache_object://localhost/%s "
            "HTTP/1.1\r\n"
            "Host: localhost\r\n"
            "Accept:*/*\r\n"
            "Connection: close\r\n\r\n",
            options[i]);
    if (__get_squid_info(options[i], msg[i], port, index) < 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<__read_squid_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2cd8(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cd5(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
jge    11ce <__read_squid_stat+0xae>
movslq -0x10(%rbp),%rax
lea    -0x420(%rbp),%rdi
shl    $0x9,%rax
add    %rax,%rdi
movslq -0x10(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rdx
lea    0xe94(%rip),%rsi
call   1040 <sprintf@plt>
movslq -0x10(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rdi
movslq -0x10(%rbp),%rax
lea    -0x420(%rbp),%rsi
shl    $0x9,%rax
add    %rax,%rsi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1030 <__get_squid_info@plt>
cmp    $0x0,%rax
jge    11bb <__read_squid_stat+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <__read_squid_stat+0xb5>
jmp    11c0 <__read_squid_stat+0xa0>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114e <__read_squid_stat+0x2e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__read_squid_stat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
lea    0xed4(%rip),%rsi
lea    0xebf(%rip),%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1040 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1030 <__get_squid_info@plt>
test   %rax,%rax
js     119d <__read_squid_stat+0x7d>
lea    0x200(%rsp),%rbx
lea    0xe9a(%rip),%rsi
lea    0xe8a(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1040 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1030 <__get_squid_info@plt>
sar    $0x3f,%rax
jmp    11a2 <__read_squid_stat+0x82>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"info\00"
@.str.1 = [9 x i8] c"counters\00"
@__const.__read_squid_stat.options = [2 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [93 x i8] c"GET cache_object://localhost/%s HTTP/1.1\0D\0AHost: localhost\0D\0AAccept:*/*\0D\0AConnection: close\0D\0A\0D\0A\00"
define i32 @__read_squid_stat(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i8*]
%8 = alloca [2 x [512 x i8]]
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = bitcast [2 x i8*]* %7 to i8*
store i32 0, i32* %6
br label %10
10: ; preds = %37, %2
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %40
13: ; preds = %10
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %8, i64 0, i64 %15
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %8, i64 0, i64 %28
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %29, i64 0, i64 0
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = call i64 @__get_squid_info(i8* %26, i8* %30, i32 %31, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %13
store i32 -1, i32* %3
br label %41
36: ; preds = %13
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %10
40: ; preds = %10
store i32 0, i32* %3
br label %41
41: ; preds = %40, %35
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [5 x i8] c"info\00"
@.str.1 = [9 x i8] c"counters\00"
@.str.2 = [93 x i8] c"GET cache_object://localhost/%s HTTP/1.1\0D\0AHost: localhost\0D\0AAccept:*/*\0D\0AConnection: close\0D\0A\0D\0A\00"
define i32 @__read_squid_stat(i32 %0, i32 %1) {
%3 = alloca [2 x [512 x i8]]
%4 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %3, i64 0, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([93 x i8], [93 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @__get_squid_info(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %0, i32 %1)
%7 = icmp slt i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = getelementptr inbounds [2 x [512 x i8]], [2 x [512 x i8]]* %3, i64 0, i64 1, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([93 x i8], [93 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%11 = call i64 @__get_squid_info(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %0, i32 %1)
%12 = ashr i64 %11, 63
%13 = trunc i64 %12 to i32
br label %14
14: ; preds = %8, %2
%15 = phi i32 [ -1, %2 ], [ %13, %8 ]
ret i32 %15
}