#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *memmem(char const *, size_t, char const *, size_t);
char *mmap_file(char *, size_t *);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "call: %s queryfile file\n", argv[0]);
    return 1;
  }
  size_t m;
  const char *q = mmap_file(argv[1], &m);
  if (!q) {
    perror(0);
    return 1;
  }
  size_t n;
  const char *t = mmap_file(argv[2], &n);
  if (!q) {
    perror(0);
    return 1;
  }
  const char *p = memmem(t, n, q, m);
  if (!p)
    return 1;
  printf("%zd\n", p - t);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1198 <main+0x48>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <main+0xfe>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <mmap_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cb <main+0x7b>
xor    %edi,%edi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <main+0xfe>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <mmap_file@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fe <main+0xae>
xor    %edi,%edi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <main+0xfe>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1050 <memmem@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    122e <main+0xde>
movl   $0x1,-0x4(%rbp)
jmp    124e <main+0xfe>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xdd7(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     1179 <main+0x29>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe8e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11d5 <main+0x85>
mov    0x8(%rbx),%rdi
lea    0x10(%rsp),%rsi
call   1070 <mmap_file@plt>
test   %rax,%rax
je     11ce <main+0x7e>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1070 <mmap_file@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rcx
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <memmem@plt>
test   %rax,%rax
je     11d5 <main+0x85>
sub    %ebx,%eax
lea    0xe56(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11da <main+0x8a>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"call: %s queryfile file\0A\00"
@.str.1 = [5 x i8] c"%zd\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %54
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i8* @mmap_file(i8* %22, i64* %6)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %28, label %26
26: ; preds = %19
%27 = call i32 @perror(i32 0)
store i32 1, i32* %3
br label %54
28: ; preds = %19
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i8* @mmap_file(i8* %31, i64* %8)
store i8* %32, i8** %9
%33 = load i8*, i8** %7
%34 = icmp ne i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %28
%36 = call i32 @perror(i32 0)
store i32 1, i32* %3
br label %54
37: ; preds = %28
%38 = load i8*, i8** %9
%39 = load i64, i64* %8
%40 = load i8*, i8** %7
%41 = load i64, i64* %6
%42 = call i8* @memmem(i8* %38, i64 %39, i8* %40, i64 %41)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
%44 = icmp ne i8* %43, null
br i1 %44, label %46, label %45
45: ; preds = %37
store i32 1, i32* %3
br label %54
46: ; preds = %37
%47 = load i8*, i8** %10
%48 = load i8*, i8** %9
%49 = ptrtoint i8* %47 to i64
%50 = ptrtoint i8* %48 to i64
%51 = sub i64 %49, %50
%52 = trunc i64 %51 to i32
%53 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %52)
store i32 0, i32* %3
br label %54
54: ; preds = %46, %45, %35, %26, %13
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"call: %s queryfile file\0A\00"
@.str.1 = [5 x i8] c"%zd\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %37
10: ; preds = %2
%11 = bitcast i64* %3 to i8*
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i8* @mmap_file(i8* %13, i64* %3)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @perror(i32 0)
br label %35
18: ; preds = %10
%19 = bitcast i64* %4 to i8*
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i8* @mmap_file(i8* %21, i64* %4)
%23 = load i64, i64* %4
%24 = load i64, i64* %3
%25 = call i8* @memmem(i8* %22, i64 %23, i8* %14, i64 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %33, label %27
27: ; preds = %18
%28 = ptrtoint i8* %25 to i64
%29 = ptrtoint i8* %22 to i64
%30 = sub i64 %28, %29
%31 = trunc i64 %30 to i32
%32 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %27, %18
%34 = phi i32 [ 0, %27 ], [ 1, %18 ]
br label %35
35: ; preds = %33, %16
%36 = phi i32 [ %34, %33 ], [ 1, %16 ]
br label %37
37: ; preds = %35, %6
%38 = phi i32 [ 1, %6 ], [ %36, %35 ]
ret i32 %38
}