#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*/ strcpy(char *, char *);
short strpos2(char *S1, char *S2, short num) {
  char STR1[256];
  short found = 0;
  short done = 0;
  short index = 0;
  strcpy(STR1, S1);
  while (!done) {
    if (STR1[index] == S2[0]) {
      found++;
    }
    if (found == num)
      done = 1;
    else
      index++;
  }
  return index;
}


x86 assembly (clang, -O0):
<strpos2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movw   $0x0,-0x122(%rbp)
movw   $0x0,-0x124(%rbp)
movw   $0x0,-0x126(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
cmpw   $0x0,-0x124(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    116f <strpos2+0x5f>
jmp    11d8 <strpos2+0xc8>
movswq -0x126(%rbp),%rax
ff
movsbl -0x120(%rbp,%rax,1),%eax
ff
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11a0 <strpos2+0x90>
mov    -0x122(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x122(%rbp)
movswl -0x122(%rbp),%eax
movswl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jne    11c1 <strpos2+0xb1>
movw   $0x1,-0x124(%rbp)
jmp    11d3 <strpos2+0xc3>
mov    -0x126(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x126(%rbp)
jmp    1155 <strpos2+0x45>
movswl -0x126(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strpos2>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    (%r14),%cl
xor    %eax,%eax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movswq %ax,%rsi
xor    %edi,%edi
cmp    %cl,(%rsp,%rsi,1)
sete   %dil
add    %edi,%edx
add    $0x1,%eax
cmp    %bx,%dx
jne    1140 <strpos2+0x30>
sete   %cl
add    $0x1,%cl
movzbl %cl,%ecx
and    $0x1,%ecx
add    %ecx,%eax
add    $0xffffffff,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define signext i16 @strpos2(i8* %0, i8* %1, i16 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i16
%7 = alloca [256 x i8]
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
store i8* %0, i8** %4
store i8* %1, i8** %5
store i16 %2, i16* %6
store i16 0, i16* %8
store i16 0, i16* %9
store i16 0, i16* %10
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i32 @strcpy(i8* %11, i8* %12)
br label %14
14: ; preds = %42, %3
%15 = load i16, i16* %9
%16 = icmp ne i16 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %43
18: ; preds = %14
%19 = load i16, i16* %10
%20 = sext i16 %19 to i64
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %23, %27
br i1 %28, label %29, label %32
29: ; preds = %18
%30 = load i16, i16* %8
%31 = add i16 %30, 1
store i16 %31, i16* %8
br label %32
32: ; preds = %29, %18
%33 = load i16, i16* %8
%34 = sext i16 %33 to i32
%35 = load i16, i16* %6
%36 = sext i16 %35 to i32
%37 = icmp eq i32 %34, %36
br i1 %37, label %38, label %39
38: ; preds = %32
store i16 1, i16* %9
br label %42
39: ; preds = %32
%40 = load i16, i16* %10
%41 = add i16 %40, 1
store i16 %41, i16* %10
br label %42
42: ; preds = %39, %38
br label %14
43: ; preds = %14
%44 = load i16, i16* %10
ret i16 %44
}

LLVM IR (-O2):
define signext i16 @strpos2(i8* %0, i8* nocapture %1, i16 signext %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = load i8, i8* %1
br label %8
8: ; preds = %3, %8
%9 = phi i16 [ 0, %3 ], [ %20, %8 ]
%10 = phi i16 [ 0, %3 ], [ %16, %8 ]
%11 = sext i16 %9 to i64
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, %7
%15 = zext i1 %14 to i16
%16 = add i16 %10, %15
%17 = icmp eq i16 %16, %2
%18 = xor i1 %17, true
%19 = zext i1 %18 to i16
%20 = add i16 %9, %19
br i1 %17, label %21, label %8
21: ; preds = %8
ret i16 %20
}