#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 */
struct assembler {
  int dummy;
};

/* Variables and functions */
char *cur_ptr(struct assembler *);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char *, size_t);
int strcmp_token(struct assembler *a, const char *s, const char delims[]) {
  char *p = cur_ptr(a);
  size_t n = strlen(s);
  if (strncmp(s, p, n)) {
    return -1;
  }
  p += n;
  if (!*p) {
    return 0;
  }
  while (*delims) {
    if (*p == *delims) {
      return 1;
    }
    ++delims;
  }
  return -1;
}


x86 assembly (clang, -O0):
<strcmp_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <cur_ptr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1185 <strcmp_token+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <strcmp_token+0xc6>
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11aa <strcmp_token+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <strcmp_token+0xc6>
jmp    11af <strcmp_token+0x7f>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ef <strcmp_token+0xbf>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11de <strcmp_token+0xae>
movl   $0x1,-0x4(%rbp)
jmp    11f6 <strcmp_token+0xc6>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11af <strcmp_token+0x7f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmp_token>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r12
call   1050 <cur_ptr@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     1178 <strcmp_token+0x48>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%r14,%r15,1),%cl
test   %cl,%cl
je     11a1 <strcmp_token+0x71>
mov    (%rbx),%dl
test   %dl,%dl
je     116c <strcmp_token+0x3c>
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
cmp    %dl,%cl
je     11a5 <strcmp_token+0x75>
movzbl (%rbx),%edx
add    $0x1,%rbx
test   %dl,%dl
jne    1190 <strcmp_token+0x60>
jmp    116c <strcmp_token+0x3c>
xor    %eax,%eax
jmp    116c <strcmp_token+0x3c>
mov    $0x1,%eax
jmp    116c <strcmp_token+0x3c>

LLVM IR (-O0):
%struct.assembler = type { i32 }
define i32 @strcmp_token(%struct.assembler* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.assembler*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store %struct.assembler* %0, %struct.assembler** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load %struct.assembler*, %struct.assembler** %5
%11 = call i8* @cur_ptr(%struct.assembler* %10)
store i8* %11, i8** %8
%12 = load i8*, i8** %6
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %9
%14 = load i8*, i8** %6
%15 = load i8*, i8** %8
%16 = load i64, i64* %9
%17 = call i64 @strncmp(i8* %14, i8* %15, i64 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 -1, i32* %4
br label %46
20: ; preds = %3
%21 = load i64, i64* %9
%22 = load i8*, i8** %8
%23 = getelementptr inbounds i8, i8* %22, i64 %21
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %20
store i32 0, i32* %4
br label %46
28: ; preds = %20
br label %29
29: ; preds = %42, %28
%30 = load i8*, i8** %7
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i8*, i8** %8
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = load i8*, i8** %7
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %36, %39
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 1, i32* %4
br label %46
42: ; preds = %33
%43 = load i8*, i8** %7
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %7
br label %29
45: ; preds = %29
store i32 -1, i32* %4
br label %46
46: ; preds = %45, %41, %27, %19
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
%struct.assembler = type { i32 }
define i32 @strcmp_token(%struct.assembler* %0, i8* %1, i8* nocapture %2) {
%4 = tail call i8* @cur_ptr(%struct.assembler* %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = tail call i64 @strncmp(i8* %1, i8* %4, i64 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %4, i64 %5
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %8
%13 = load i8, i8* %2
%14 = icmp eq i8 %13, 0
br i1 %14, label %23, label %18
15: ; preds = %18
%16 = load i8, i8* %22
%17 = icmp eq i8 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %12, %15
%19 = phi i8 [ %16, %15 ], [ %13, %12 ]
%20 = phi i8* [ %22, %15 ], [ %2, %12 ]
%21 = icmp eq i8 %10, %19
%22 = getelementptr inbounds i8, i8* %20, i64 1
br i1 %21, label %23, label %15
23: ; preds = %18, %15, %12, %8, %3
%24 = phi i32 [ -1, %3 ], [ 0, %8 ], [ -1, %12 ], [ 1, %18 ], [ -1, %15 ]
ret i32 %24
}