#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
int expect_string(FILE *fp, char *str) {
  assert(str != NULL);
  int ch;
  char *start = str;
  while (*str != '\0' && (ch = fgetc(fp)) != EOF) {
    if (*str != ch)
      break;
    str++;
  }
  if (*str == '\0')
    return 1;
  ungetc(ch, fp);
  while (str-- != start) {
    ungetc(*str, fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<expect_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     118a <expect_string+0x5a>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    119a <expect_string+0x6a>
jmp    11c0 <expect_string+0x90>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x1c(%rbp),%eax
je     11af <expect_string+0x7f>
jmp    11c0 <expect_string+0x90>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115a <expect_string+0x2a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11dc <expect_string+0xac>
movl   $0x1,-0x4(%rbp)
jmp    1222 <expect_string+0xf2>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1050 <ungetc@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    -0x28(%rbp),%rax
je     121b <expect_string+0xeb>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1050 <ungetc@plt>
jmp    11eb <expect_string+0xbb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expect_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
mov    $0x1,%r15d
cmpb   $0x0,(%rbx)
je     11b3 <expect_string+0x83>
xor    %ebp,%ebp
mov    0x2e88(%rip),%r12
mov    %r14,%rdi
call   1030 <fgetc@plt>
movzbl (%rbx,%rbp,1),%ecx
cmp    (%r12),%eax
je     1186 <expect_string+0x56>
movsbl %cl,%edx
cmp    %edx,%eax
jne    1186 <expect_string+0x56>
cmpb   $0x0,0x1(%rbx,%rbp,1)
lea    0x1(%rbp),%rbp
jne    1160 <expect_string+0x30>
jmp    11b3 <expect_string+0x83>
test   %cl,%cl
je     11b3 <expect_string+0x83>
movsbl %al,%edi
mov    %r14,%rsi
call   1050 <ungetc@plt>
xor    %r15d,%r15d
test   %rbp,%rbp
je     11b3 <expect_string+0x83>
nopl   (%rax)
movsbl -0x1(%rbx,%rbp,1),%edi
mov    %r14,%rsi
call   1050 <ungetc@plt>
add    $0xffffffffffffffff,%rbp
jne    11a0 <expect_string+0x70>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @expect_string(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %5
store i8* %12, i8** %7
br label %13
13: ; preds = %32, %2
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i32*, i32** %4
%20 = call i32 @fgetc(i32* %19)
store i32 %20, i32* %6
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br label %23
23: ; preds = %18, %13
%24 = phi i1 [ false, %13 ], [ %22, %18 ]
br i1 %24, label %25, label %35
25: ; preds = %23
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i32, i32* %6
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %25
br label %35
32: ; preds = %25
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %5
br label %13
35: ; preds = %31, %23
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 1, i32* %3
br label %57
41: ; preds = %35
%42 = load i32, i32* %6
%43 = trunc i32 %42 to i8
%44 = load i32*, i32** %4
%45 = call i32 @ungetc(i8 signext %43, i32* %44)
br label %46
46: ; preds = %51, %41
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i32 -1
store i8* %48, i8** %5
%49 = load i8*, i8** %7
%50 = icmp ne i8* %47, %49
br i1 %50, label %51, label %56
51: ; preds = %46
%52 = load i8*, i8** %5
%53 = load i8, i8* %52
%54 = load i32*, i32** %4
%55 = call i32 @ungetc(i8 signext %53, i32* %54)
br label %46
56: ; preds = %46
store i32 0, i32* %3
br label %57
57: ; preds = %56, %40
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @expect_string(i32* nocapture %0, i8* %1) {
%3 = icmp ne i8* %1, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 0
br i1 %7, label %33, label %8
8: ; preds = %2, %17
%9 = phi i8* [ %18, %17 ], [ %1, %2 ]
%10 = tail call i32 @fgetc(i32* %0)
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
%13 = load i8, i8* %9
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %10, %14
%16 = select i1 %12, i1 %15, i1 false
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = getelementptr inbounds i8, i8* %9, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %33, label %8
21: ; preds = %8
%22 = icmp eq i8 %13, 0
br i1 %22, label %33, label %23
23: ; preds = %21
%24 = trunc i32 %10 to i8
%25 = tail call i32 @ungetc(i8 signext %24, i32* %0)
%26 = icmp eq i8* %9, %1
br i1 %26, label %33, label %27
27: ; preds = %23, %27
%28 = phi i8* [ %29, %27 ], [ %9, %23 ]
%29 = getelementptr inbounds i8, i8* %28, i64 -1
%30 = load i8, i8* %29
%31 = tail call i32 @ungetc(i8 signext %30, i32* %0)
%32 = icmp eq i8* %29, %1
br i1 %32, label %33, label %27
33: ; preds = %17, %27, %2, %23, %21
%34 = phi i32 [ 1, %21 ], [ 0, %23 ], [ 1, %2 ], [ 0, %27 ], [ 1, %17 ]
ret i32 %34
}