#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 uint32_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int const);
int /*<<< orphan*/ memset(char *, char, int const);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
double strstr_wrapper(char *, char *);
int main(int argc, char *argv[]) {
  if (argc == 1)
    return EXIT_SUCCESS;
  const uint32_t MiB = 1024 * 1024;
  const uint32_t size = 16 * MiB;
  char *buffer = (char *)malloc(size);
  if (buffer == NULL)
    return EXIT_FAILURE;
  memset(buffer, '?', size);
  buffer[size - 1] = '\0';
  for (int i = 1; i < argc; i++) {
    printf("searching string '%s'... ", argv[i]);
    fflush(stdout);
    const double dt = strstr_wrapper(buffer, argv[i]);
    printf("time: %0.3f\n", dt);
  }
  free(buffer);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1191 <main+0x31>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <main+0x112>
movl   $0x100000,-0x14(%rbp)
movl   $0x1000000,-0x18(%rbp)
mov    $0x1000000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c9 <main+0x69>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <main+0x112>
mov    -0x20(%rbp),%rdi
mov    $0x3f,%esi
mov    $0x1000000,%edx
call   1060 <memset@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0xffffff(%rax)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125d <main+0xfd>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strstr_wrapper@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xdd2(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ee <main+0x8e>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rax
cmp    $0x1,%edi
je     1221 <main+0xc1>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1000000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     121a <main+0xba>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x3f,%esi
mov    $0x1000000,%edx
call   1060 <memset@plt>
movb   $0x0,0xffffff(%r14)
cmp    $0x2,%ebp
jl     1209 <main+0xa9>
mov    %ebp,%ebp
mov    $0x1,%r13d
mov    0x2e14(%rip),%r15
lea    0xe4f(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%r13,8),%rsi
lea    0xe25(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%edi
call   1080 <fflush@plt>
mov    (%rbx,%r13,8),%rsi
mov    %r14,%rdi
call   1040 <strstr_wrapper@plt>
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%r13
cmp    %r13,%rbp
jne    11d0 <main+0x70>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2db8(%rip),%rax
jmp    1221 <main+0xc1>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [26 x i8] c"searching string '%s'... \00"
@stdout = global i32 0
@.str.1 = [13 x i8] c"time: %0.3f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* @EXIT_SUCCESS
store i32 %14, i32* %3
br label %56
15: ; preds = %2
store i32 1048576, i32* %6
store i32 16777216, i32* %7
%16 = call i64 @malloc(i32 16777216)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %56
22: ; preds = %15
%23 = load i8*, i8** %8
%24 = call i32 @memset(i8* %23, i8 signext 63, i32 16777216)
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 16777215
store i8 0, i8* %26
store i32 1, i32* %9
br label %27
27: ; preds = %49, %22
%28 = load i32, i32* %9
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %52
31: ; preds = %27
%32 = load i8**, i8*** %5
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @stdout
%39 = call i32 @fflush(i32 %38)
%40 = load i8*, i8** %8
%41 = load i8**, i8*** %5
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = call double @strstr_wrapper(i8* %40, i8* %45)
store double %46, double* %10
%47 = load double, double* %10
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %47)
br label %49
49: ; preds = %31
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %27
52: ; preds = %27
%53 = load i8*, i8** %8
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* @EXIT_SUCCESS
store i32 %55, i32* %3
br label %56
56: ; preds = %52, %20, %13
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [26 x i8] c"searching string '%s'... \00"
@stdout = global i32 0
@.str.1 = [13 x i8] c"time: %0.3f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %28, label %4
4: ; preds = %2
%5 = tail call i64 @malloc(i32 16777216)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %28, label %8
8: ; preds = %4
%9 = tail call i32 @memset(i8* %6, i8 signext 63, i32 16777216)
%10 = getelementptr inbounds i8, i8* %6, i64 16777215
store i8 0, i8* %10
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = zext i32 %0 to i64
br label %16
14: ; preds = %16, %8
%15 = tail call i32 @free(i8* %6)
br label %28
16: ; preds = %12, %16
%17 = phi i64 [ 1, %12 ], [ %26, %16 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @stdout
%22 = tail call i32 @fflush(i32 %21)
%23 = load i8*, i8** %18
%24 = tail call double @strstr_wrapper(i8* %6, i8* %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double %24)
%26 = add nuw nsw i64 %17, 1
%27 = icmp eq i64 %26, %13
br i1 %27, label %14, label %16
28: ; preds = %14, %4, %2
%29 = phi i32* [ @EXIT_SUCCESS, %2 ], [ @EXIT_SUCCESS, %14 ], [ @EXIT_FAILURE, %4 ]
%30 = load i32, i32* %29
ret i32 %30
}