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

/* Variables and functions */
scalar_t__ fork_exec_read(char *, int, char *, char *, char *, char *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *malloc(size_t);
size_t snprintf(char *, size_t, char *, char *, int, int);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *, int *, double *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int http_test(char *instr, char **outstr) {
  int retval = -1;
  char buf[1024] = {
      0,
  };
  int buflen = sizeof(buf);
  char code0[64], code1[64];
  int size;
  double time;
  char *str = NULL;
  size_t slen;
  char *host = instr;
  if (fork_exec_read(buf, buflen, "/usr/lib/nagios/plugins/check_http", "--ssl",
                     "-H", host, NULL) < 0) {
    if (strlen(buf))
      fprintf(stderr, "%s\n", buf);
    goto done;
  }
  sscanf(buf, "%*s %*s %*s %s %s %*s %d %*s %*s %lf\n", code0, code1, &size,
         &time);
  if ((slen = snprintf(NULL, 0,
                       "<hstatus>\"%s\"</hstatus>"
                       "<htime>%d</htime>"
                       "<hsize>%d</hsize>",
                       code0, (int)(time * 1000), size)) <= 0)
    goto done;
  if ((str = malloc(slen + 1)) == NULL)
    goto done;
  if ((slen = snprintf(str, slen + 1,
                       "<hstatus>\"%s\"</hstatus>"
                       "<htime>%d</htime>"
                       "<hsize>%d</hsize>",
                       code0, (int)(time * 1000), size)) <= 0)
    goto done;
  *outstr = str;
  retval = 0;
done:
  return retval;
}


x86 assembly (clang, -O0):
<http_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x400,-0x424(%rbp)
movq   $0x0,-0x4c8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x4d8(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%esi
mov    -0x4d8(%rbp),%r9
lea    0xe30(%rip),%rdx
lea    0xe4c(%rip),%rcx
lea    0xe4b(%rip),%r8
xor    %eax,%eax
movq   $0x0,(%rsp)
call   1030 <fork_exec_read@plt>
cmp    $0x0,%rax
jge    1236 <http_test+0xc6>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     1231 <http_test+0xc1>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xe08(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1343 <http_test+0x1d3>
lea    -0x420(%rbp),%rdi
lea    -0x470(%rbp),%rdx
lea    -0x4b0(%rbp),%rcx
lea    0xde6(%rip),%rsi
lea    -0x4b4(%rbp),%r8
lea    -0x4c0(%rbp),%r9
call   1090 <sscanf@plt>
lea    -0x470(%rbp),%rcx
movsd  0xd8c(%rip),%xmm0
mulsd  -0x4c0(%rbp),%xmm0
ff
cvttsd2si %xmm0,%r8d
mov    -0x4b4(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%esi
lea    0xdcb(%rip),%rdx
mov    %rsi,%rdi
call   1050 <snprintf@plt>
mov    %rax,-0x4d0(%rbp)
cmp    $0x0,%rax
ja     12b1 <http_test+0x141>
jmp    1343 <http_test+0x1d3>
mov    -0x4d0(%rbp),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x4c8(%rbp)
cmp    $0x0,%rax
jne    12d7 <http_test+0x167>
jmp    1343 <http_test+0x1d3>
mov    -0x4c8(%rbp),%rdi
mov    -0x4d0(%rbp),%rsi
add    $0x1,%rsi
lea    -0x470(%rbp),%rcx
movsd  0xd08(%rip),%xmm0
mulsd  -0x4c0(%rbp),%xmm0
ff
cvttsd2si %xmm0,%r8d
mov    -0x4b4(%rbp),%r9d
lea    0xd4b(%rip),%rdx
call   1050 <snprintf@plt>
mov    %rax,-0x4d0(%rbp)
cmp    $0x0,%rax
ja     132e <http_test+0x1be>
jmp    1343 <http_test+0x1d3>
mov    -0x4c8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4a8,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xa0(%rsp),%rbp
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movq   $0x0,(%rsp)
lea    0xe6f(%rip),%rdx
lea    0xe8b(%rip),%rcx
lea    0xe8a(%rip),%r8
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%r9
call   1030 <fork_exec_read@plt>
test   %rax,%rax
js     1272 <http_test+0x112>
lea    0xe71(%rip),%rsi
lea    0xa0(%rsp),%rdi
lea    0x20(%rsp),%rbx
lea    0x60(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0x18(%rsp),%r9
mov    %rbx,%rdx
call   1080 <sscanf@plt>
movsd  0x18(%rsp),%xmm0
mulsd  0xe07(%rip),%xmm0
cvttsd2si %xmm0,%r8d
mov    0x14(%rsp),%r9d
lea    0xe54(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     129e <http_test+0x13e>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     129e <http_test+0x13e>
mov    %rax,%r15
movsd  0x18(%rsp),%xmm0
mulsd  0xdbb(%rip),%xmm0
cvttsd2si %xmm0,%r8d
mov    0x14(%rsp),%r9d
lea    0xe08(%rip),%rdx
lea    0x20(%rsp),%rcx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <snprintf@plt>
test   %rax,%rax
je     129e <http_test+0x13e>
mov    %r15,(%r14)
xor    %ebp,%ebp
jmp    129e <http_test+0x13e>
mov    $0xffffffff,%ebp
cmpb   $0x0,0xa0(%rsp)
je     129e <http_test+0x13e>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
lea    0xa0(%rsp),%rdx
call   1060 <fprintf@plt>
mov    %ebp,%eax
add    $0x4a8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"/usr/lib/nagios/plugins/check_http\00"
@.str.1 = [6 x i8] c"--ssl\00"
@.str.2 = [3 x i8] c"-H\00"
@stderr = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [38 x i8] c"%*s %*s %*s %s %s %*s %d %*s %*s %lf\0A\00"
@.str.5 = [58 x i8] c"<hstatus>\22%s\22</hstatus><htime>%d</htime><hsize>%d</hsize>\00"
define i32 @http_test(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca [64 x i8]
%9 = alloca [64 x i8]
%10 = alloca i32
%11 = alloca double
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 -1, i32* %5
%15 = bitcast [1024 x i8]* %6 to i8*
store i32 1024, i32* %7
store i8* null, i8** %12
%16 = load i8*, i8** %3
store i8* %16, i8** %14
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* %7
%19 = load i8*, i8** %14
%20 = call i64 @fork_exec_read(i8* %17, i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32* null)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %2
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %26, %22
br label %65
31: ; preds = %2
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%35 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %34, i32* %10, double* %11)
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%37 = load double, double* %11
%38 = fmul double %37, 1.000000e+03
%39 = fptosi double %38 to i32
%40 = load i32, i32* %10
%41 = call i64 @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i8* %36, i32 %39, i32 %40)
store i64 %41, i64* %13
%42 = icmp ule i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %31
br label %65
44: ; preds = %31
%45 = load i64, i64* %13
%46 = add i64 %45, 1
%47 = call i8* @malloc(i64 %46)
store i8* %47, i8** %12
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %50
49: ; preds = %44
br label %65
50: ; preds = %44
%51 = load i8*, i8** %12
%52 = load i64, i64* %13
%53 = add i64 %52, 1
%54 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%55 = load double, double* %11
%56 = fmul double %55, 1.000000e+03
%57 = fptosi double %56 to i32
%58 = load i32, i32* %10
%59 = call i64 @snprintf(i8* %51, i64 %53, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i8* %54, i32 %57, i32 %58)
store i64 %59, i64* %13
%60 = icmp ule i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %50
br label %65
62: ; preds = %50
%63 = load i8*, i8** %12
%64 = load i8**, i8*** %4
store i8* %63, i8** %64
store i32 0, i32* %5
br label %65
65: ; preds = %62, %61, %49, %43, %30
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
@.str = [35 x i8] c"/usr/lib/nagios/plugins/check_http\00"
@.str.1 = [6 x i8] c"--ssl\00"
@.str.2 = [3 x i8] c"-H\00"
@stderr = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [38 x i8] c"%*s %*s %*s %s %s %*s %d %*s %*s %lf\0A\00"
@.str.5 = [58 x i8] c"<hstatus>\22%s\22</hstatus><htime>%d</htime><hsize>%d</hsize>\00"
define i32 @http_test(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca [1024 x i8]
%4 = alloca [64 x i8]
%5 = alloca [64 x i8]
%6 = alloca i32
%7 = alloca double
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%11 = bitcast i32* %6 to i8*
%12 = bitcast double* %7 to i8*
%13 = call i64 @fork_exec_read(i8* %8, i32 1024, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32* null)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8, i8* %8
%17 = icmp eq i8 %16, 0
br i1 %17, label %41, label %18
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %8)
br label %41
21: ; preds = %2
%22 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %9, i8* %10, i32* %6, double* %7)
%23 = load double, double* %7
%24 = fmul double %23, 1.000000e+03
%25 = fptosi double %24 to i32
%26 = load i32, i32* %6
%27 = call i64 @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i8* %9, i32 %25, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %41, label %29
29: ; preds = %21
%30 = add i64 %27, 1
%31 = call i8* @malloc(i64 %30)
%32 = icmp eq i8* %31, null
br i1 %32, label %41, label %33
33: ; preds = %29
%34 = load double, double* %7
%35 = fmul double %34, 1.000000e+03
%36 = fptosi double %35 to i32
%37 = load i32, i32* %6
%38 = call i64 @snprintf(i8* %31, i64 %30, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i8* %9, i32 %36, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %33
store i8* %31, i8** %1
br label %41
41: ; preds = %33, %29, %21, %15, %18, %40
%42 = phi i32 [ -1, %18 ], [ -1, %15 ], [ -1, %21 ], [ -1, %29 ], [ -1, %33 ], [ 0, %40 ]
ret i32 %42
}