#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
long atol(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
long spawn_benchmark(const char *cmd) {
  char *s, *p;
  const size_t buf_size = 4096;
  char buf[buf_size];
  FILE *f;
  f = popen(cmd, "r");
  while (fgets(buf, sizeof(buf) - 1, f)) {
    if (strncmp(buf, "finished ", 9) == 0) {
      s = strstr(buf, " req/s,");
      if (!s) {
        printf("Error: Invalid benchmarking tool output\n");
        exit(EXIT_FAILURE);
      }
      p = (s - 1);
      while (*p != ' ')
        *p--;
      *p++;
      strncpy(buf, p, (s - p));
      buf[(s - p)] = '\0';
      break;
    }
  }
  fclose(f);
  return atol(buf);
}


x86 assembly (clang, -O0):
<spawn_benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1000,-0x20(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdx
lea    -0x1030(%rbp),%rdi
mov    $0xfff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12b2 <spawn_benchmark+0x122>
lea    -0x1030(%rbp),%rdi
lea    0xe13(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12ad <spawn_benchmark+0x11d>
lea    -0x1030(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    123f <spawn_benchmark+0xaf>
lea    0xde8(%rip),%rdi
call   1060 <printf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     126c <spawn_benchmark+0xdc>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    124b <spawn_benchmark+0xbb>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
lea    -0x1030(%rbp),%rdi
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x1030(%rbp,%rax,1)
jmp    12b2 <spawn_benchmark+0x122>
jmp    11c2 <spawn_benchmark+0x32>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x1030(%rbp),%rdi
call   1080 <atol@plt>
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spawn_benchmark>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
lea    0xe5d(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,%r14
mov    %rsp,%rbx
lea    0xe4d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0xfff,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     122f <spawn_benchmark+0x9f>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11c0 <spawn_benchmark+0x30>
lea    0xe1b(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <strstr@plt>
test   %rax,%rax
je     124c <spawn_benchmark+0xbc>
add    $0x1,%rax
mov    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
add    $0x1,%rbx
cmpb   $0x20,-0x2(%rax)
lea    -0x1(%rax),%rax
jne    1210 <spawn_benchmark+0x80>
mov    %rsp,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %rsp,%rdi
call   1080 <atol@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdc1(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"finished \00"
@.str.2 = [8 x i8] c" req/s,\00"
@.str.3 = [41 x i8] c"Error: Invalid benchmarking tool output\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @spawn_benchmark(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %2
store i64 4096, i64* %5
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %6
%9 = alloca i8, i64 4096
%10 = load i8*, i8** %2
%11 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
br label %12
12: ; preds = %57, %1
%13 = load i32*, i32** %7
%14 = call i64 @fgets(i8* %9, i32 4095, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %58
16: ; preds = %12
%17 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %57
19: ; preds = %16
%20 = call i8* @strstr(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = icmp ne i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 -1
store i8* %29, i8** %4
br label %30
30: ; preds = %35, %27
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 32
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %4
%38 = load i8, i8* %36
br label %30
39: ; preds = %30
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %4
%42 = load i8, i8* %40
%43 = load i8*, i8** %4
%44 = load i8*, i8** %3
%45 = load i8*, i8** %4
%46 = ptrtoint i8* %44 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
%49 = trunc i64 %48 to i32
%50 = call i32 @strncpy(i8* %9, i8* %43, i32 %49)
%51 = load i8*, i8** %3
%52 = load i8*, i8** %4
%53 = ptrtoint i8* %51 to i64
%54 = ptrtoint i8* %52 to i64
%55 = sub i64 %53, %54
%56 = getelementptr inbounds i8, i8* %9, i64 %55
store i8 0, i8* %56
br label %58
57: ; preds = %16
br label %12
58: ; preds = %39, %12
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
%61 = call i64 @atol(i8* %9)
%62 = load i8*, i8** %6
ret i64 %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"finished \00"
@.str.2 = [8 x i8] c" req/s,\00"
@EXIT_FAILURE = global i32 0
@str = [40 x i8] c"Error: Invalid benchmarking tool output\00"
define i64 @spawn_benchmark(i8* nocapture %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %8, %1
%6 = call i64 @fgets(i8* %3, i32 4095, i32* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %30, label %8
8: ; preds = %5
%9 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %5
11: ; preds = %8
%12 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %11, %18
%19 = phi i8* [ %20, %18 ], [ %12, %11 ]
%20 = getelementptr inbounds i8, i8* %19, i64 -1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 32
br i1 %22, label %23, label %18
23: ; preds = %18
%24 = ptrtoint i8* %12 to i64
%25 = ptrtoint i8* %19 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
%28 = call i32 @strncpy(i8* %3, i8* %19, i32 %27)
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 %26
store i8 0, i8* %29
br label %30
30: ; preds = %5, %23
%31 = call i32 @fclose(i32* %4)
%32 = call i64 @atol(i8* %3)
ret i64 %32
}