#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 */
char *strstr(char *, char *);
int pos(char *findstr, char *source) {
  char *pdest;
  if ((findstr == NULL) || (source == NULL))
    return 0;
  pdest = strstr(source, findstr);
  if (pdest == NULL)
    return 0;
  else
    return pdest + 1 - source;
}


x86 assembly (clang, -O0):
<pos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1136 <pos+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1142 <pos+0x32>
movl   $0x0,-0x4(%rbp)
jmp    117c <pos+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116a <pos+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    117c <pos+0x6c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pos>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     1139 <pos+0x29>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1139 <pos+0x29>
mov    %rdi,%rsi
mov    %rbx,%rdi
call   1030 <strstr@plt>
test   %rax,%rax
je     1139 <pos+0x29>
sub    %ebx,%eax
add    $0x1,%eax
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pos(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i32 0, i32* %3
br label %28
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i8*, i8** %4
%16 = call i8* @strstr(i8* %14, i8* %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 0, i32* %3
br label %28
20: ; preds = %13
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8*, i8** %5
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
store i32 %27, i32* %3
br label %28
28: ; preds = %20, %19, %12
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @pos(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = tail call i8* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = ptrtoint i8* %10 to i64
%12 = ptrtoint i8* %1 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %6, %2, %9
%16 = phi i32 [ %14, %9 ], [ 0, %2 ], [ 0, %6 ]
ret i32 %16
}