#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 strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int isapiline(char *buf, char *api) {
  char *s;
  if (!strncmp(buf, api, strlen(api)))
    return (strlen(api));
  s = buf;
  while (*s && *s > ' ')
    s++;
  if ((s - buf) > 4) {
    if (!strncmp(s - 4, "_API", 4))
      return (s - buf);
  }
  return (0);
}


x86 assembly (clang, -O0):
<isapiline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1172 <isapiline+0x52>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    1216 <isapiline+0xf6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     119f <isapiline+0x7f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setg   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11af <isapiline+0x8f>
jmp    11c0 <isapiline+0xa0>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117a <isapiline+0x5a>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x4,%rax
jle    120f <isapiline+0xef>
mov    -0x20(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe1c(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    120a <isapiline+0xea>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    1216 <isapiline+0xf6>
jmp    120f <isapiline+0xef>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isapiline>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     118a <isapiline+0x6a>
add    $0xfffffffffffffffb,%r15
mov    $0xffffffffffffffff,%rbx
nop
add    $0x1,%rbx
cmpb   $0x20,0x5(%r15)
lea    0x1(%r15),%r15
jg     1150 <isapiline+0x30>
xor    %eax,%eax
cmp    $0x5,%rbx
jl     1184 <isapiline+0x64>
lea    0xe92(%rip),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovne %ecx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <strlen@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"_API\00"
define i32 @isapiline(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 = load i8*, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @strncmp(i8* %7, i8* %8, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %3
br label %54
16: ; preds = %2
%17 = load i8*, i8** %4
store i8* %17, i8** %6
br label %18
18: ; preds = %30, %16
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp sgt i32 %26, 32
br label %28
28: ; preds = %23, %18
%29 = phi i1 [ false, %18 ], [ %27, %23 ]
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %6
br label %18
33: ; preds = %28
%34 = load i8*, i8** %6
%35 = load i8*, i8** %4
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = icmp sgt i64 %38, 4
br i1 %39, label %40, label %53
40: ; preds = %33
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i64 -4
%43 = call i32 @strncmp(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%44 = icmp ne i32 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %40
%46 = load i8*, i8** %6
%47 = load i8*, i8** %4
%48 = ptrtoint i8* %46 to i64
%49 = ptrtoint i8* %47 to i64
%50 = sub i64 %48, %49
%51 = trunc i64 %50 to i32
store i32 %51, i32* %3
br label %54
52: ; preds = %40
br label %53
53: ; preds = %52, %33
store i32 0, i32* %3
br label %54
54: ; preds = %53, %45, %13
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [5 x i8] c"_API\00"
define i32 @isapiline(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %1)
br label %24
8: ; preds = %2, %8
%9 = phi i8* [ %12, %8 ], [ %0, %2 ]
%10 = load i8, i8* %9
%11 = icmp sgt i8 %10, 32
%12 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %11, label %8, label %13
13: ; preds = %8
%14 = ptrtoint i8* %9 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = icmp sgt i64 %16, 4
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = getelementptr inbounds i8, i8* %9, i64 -4
%20 = tail call i32 @strncmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%21 = icmp eq i32 %20, 0
%22 = trunc i64 %16 to i32
%23 = select i1 %21, i32 %22, i32 0
br label %24
24: ; preds = %18, %13, %6
%25 = phi i32 [ %7, %6 ], [ 0, %13 ], [ %23, %18 ]
ret i32 %25
}