#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 stream {
  int dummy;
};

/* Variables and functions */
int efp_stream_advance(struct stream *, int /*<<< orphan*/);
scalar_t__ efp_stream_eol(struct stream *);
int /*<<< orphan*/ efp_stream_get_ptr(struct stream *);
int /*<<< orphan*/ efp_stream_skip_space(struct stream *);
scalar_t__ efp_strncasecmp(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int tok(struct stream *stream, const char *id) {
  efp_stream_skip_space(stream);
  if (efp_stream_eol(stream))
    return 0;
  if (efp_strncasecmp(efp_stream_get_ptr(stream), id, strlen(id)) == 0)
    return efp_stream_advance(stream, strlen(id));
  return 0;
}


x86 assembly (clang, -O0):
<tok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <efp_stream_skip_space@plt>
mov    -0x10(%rbp),%rdi
call   1070 <efp_stream_eol@plt>
cmp    $0x0,%rax
je     1198 <tok+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11f8 <tok+0x98>
mov    -0x10(%rbp),%rdi
call   1040 <efp_stream_get_ptr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <efp_strncasecmp@plt>
cmp    $0x0,%rax
jne    11f1 <tok+0x91>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1050 <efp_stream_advance@plt>
mov    %eax,-0x4(%rbp)
jmp    11f8 <tok+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tok>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1080 <efp_stream_skip_space@plt>
mov    %rbx,%rdi
call   1070 <efp_stream_eol@plt>
test   %rax,%rax
jne    119f <tok+0x3f>
mov    %rbx,%rdi
call   1040 <efp_stream_get_ptr@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <efp_strncasecmp@plt>
test   %rax,%rax
je     11a6 <tok+0x46>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <efp_stream_advance@plt>

LLVM IR (-O0):
%struct.stream = type { i32 }
define i32 @tok(%struct.stream* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.stream*
%5 = alloca i8*
store %struct.stream* %0, %struct.stream** %4
store i8* %1, i8** %5
%6 = load %struct.stream*, %struct.stream** %4
%7 = call i32 @efp_stream_skip_space(%struct.stream* %6)
%8 = load %struct.stream*, %struct.stream** %4
%9 = call i64 @efp_stream_eol(%struct.stream* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %26
12: ; preds = %2
%13 = load %struct.stream*, %struct.stream** %4
%14 = call i32 @efp_stream_get_ptr(%struct.stream* %13)
%15 = load i8*, i8** %5
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = call i64 @efp_strncasecmp(i32 %14, i8* %15, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %12
%21 = load %struct.stream*, %struct.stream** %4
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @efp_stream_advance(%struct.stream* %21, i32 %23)
store i32 %24, i32* %3
br label %26
25: ; preds = %12
store i32 0, i32* %3
br label %26
26: ; preds = %25, %20, %11
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.stream = type { i32 }
define i32 @tok(%struct.stream* %0, i8* %1) {
%3 = tail call i32 @efp_stream_skip_space(%struct.stream* %0)
%4 = tail call i64 @efp_stream_eol(%struct.stream* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = tail call i32 @efp_stream_get_ptr(%struct.stream* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i64 @efp_strncasecmp(i32 %7, i8* %1, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i32 @strlen(i8* %1)
%13 = tail call i32 @efp_stream_advance(%struct.stream* %0, i32 %12)
br label %14
14: ; preds = %6, %2, %11
%15 = phi i32 [ %13, %11 ], [ 0, %2 ], [ 0, %6 ]
ret i32 %15
}