#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 */
scalar_t__ memcmp(char *, char const *, int);
int getwpapskfmt(int lenlinein, char *linein) {
  static int p;
  static const char *johnformat = "$WPAPSK$";
  for (p = 0; p < lenlinein - 8; p++) {
    if (memcmp(&linein[p], johnformat, 8) == 0)
      return p;
  }
  return 0;
}


x86 assembly (clang, -O0):
<getwpapskfmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,0x2f0b(%rip)
mov    0x2f05(%rip),%eax
mov    -0x8(%rbp),%ecx
sub    $0x8,%ecx
cmp    %ecx,%eax
jge    118d <getwpapskfmt+0x7d>
mov    -0x10(%rbp),%rdi
movslq 0x2eec(%rip),%rax
add    %rax,%rdi
mov    0x2ed6(%rip),%rsi
mov    $0x8,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1174 <getwpapskfmt+0x64>
mov    0x2ec8(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <getwpapskfmt+0x84>
jmp    1179 <getwpapskfmt+0x69>
mov    0x2eb5(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2eac(%rip)
jmp    1129 <getwpapskfmt+0x19>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getwpapskfmt>:
push   %rbp
push   %r14
push   %rbx
movl   $0x0,0x2f0e(%rip)
xor    %eax,%eax
cmp    $0x9,%edi
jl     1170 <getwpapskfmt+0x60>
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0xfffffff8,%ebp
xor    %eax,%eax
lea    0xeca(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movslq %eax,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1030 <memcmp@plt>
mov    %rax,%rcx
mov    0x2ed0(%rip),%eax
test   %rcx,%rcx
je     1170 <getwpapskfmt+0x60>
add    $0x1,%eax
mov    %eax,0x2ec2(%rip)
cmp    %ebp,%eax
jl     1140 <getwpapskfmt+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@getwpapskfmt.p = internal global i32 0
@getwpapskfmt.johnformat = internal global i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0)
@.str = [9 x i8] c"$WPAPSK$\00"
define i32 @getwpapskfmt(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* @getwpapskfmt.p
br label %6
6: ; preds = %22, %2
%7 = load i32, i32* @getwpapskfmt.p
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 8
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %25
11: ; preds = %6
%12 = load i8*, i8** %5
%13 = load i32, i32* @getwpapskfmt.p
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8*, i8** @getwpapskfmt.johnformat
%17 = call i64 @memcmp(i8* %15, i8* %16, i32 8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = load i32, i32* @getwpapskfmt.p
store i32 %20, i32* %3
br label %26
21: ; preds = %11
br label %22
22: ; preds = %21
%23 = load i32, i32* @getwpapskfmt.p
%24 = add nsw i32 %23, 1
store i32 %24, i32* @getwpapskfmt.p
br label %6
25: ; preds = %6
store i32 0, i32* %3
br label %26
26: ; preds = %25, %19
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@getwpapskfmt.p = internal unnamed_addr global i32 0
@.str = [9 x i8] c"$WPAPSK$\00"
define i32 @getwpapskfmt(i32 %0, i8* %1) {
%3 = add nsw i32 %0, -8
store i32 0, i32* @getwpapskfmt.p
%4 = icmp sgt i32 %0, 8
br i1 %4, label %5, label %15
5: ; preds = %2, %12
%6 = phi i32 [ %13, %12 ], [ 0, %2 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = tail call i64 @memcmp(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%10 = icmp eq i64 %9, 0
%11 = load i32, i32* @getwpapskfmt.p
br i1 %10, label %15, label %12
12: ; preds = %5
%13 = add nsw i32 %11, 1
store i32 %13, i32* @getwpapskfmt.p
%14 = icmp slt i32 %13, %3
br i1 %14, label %5, label %15
15: ; preds = %12, %5, %2
%16 = phi i32 [ 0, %2 ], [ %11, %5 ], [ 0, %12 ]
ret i32 %16
}