#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 /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char read_char(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
size_t strlen(char *);
void expect(FILE *file, char *str) {
  if (!strlen(str))
    return;
  char *s = malloc(sizeof(char) * (strlen(str) + 1));
  size_t i;
  s[0] = read_char(file, 1);
  for (i = 1; i < strlen(str); ++i) {
    s[i] = fgetc(file);
  }
  s[i] = '\0';
  if (strcmp(s, str)) {
    fprintf(stderr, "Expected \"%s\", but got \"%s\"\n", str, s);
    exit(1);
  }
  free(s);
}


x86 assembly (clang, -O0):
<expect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11a8 <expect+0x28>
jmp    127d <expect+0xfd>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1090 <read_char@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    122a <expect+0xaa>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11e2 <expect+0x62>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1274 <expect+0xf4>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd9b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expect>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1225 <expect+0xa5>
add    $0x1,%eax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    $0x1,%esi
call   1090 <read_char@plt>
mov    %al,(%r12)
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x1,%ebx
cmp    $0x2,%rax
jb     11fd <expect+0x7d>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jb     11e0 <expect+0x60>
movb   $0x0,(%r12,%rbx,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1231 <expect+0xb1>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Expected \22%s\22, but got \22%s\22\0A\00"
define void @expect(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %2
br label %53
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = add i64 %13, 1
%15 = mul i64 1, %14
%16 = trunc i64 %15 to i32
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %5
%18 = load i32*, i32** %3
%19 = call signext i8 @read_char(i32* %18, i32 1)
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 %19, i8* %21
store i64 1, i64* %6
br label %22
22: ; preds = %33, %11
%23 = load i64, i64* %6
%24 = load i8*, i8** %4
%25 = call i64 @strlen(i8* %24)
%26 = icmp ult i64 %23, %25
br i1 %26, label %27, label %36
27: ; preds = %22
%28 = load i32*, i32** %3
%29 = call signext i8 @fgetc(i32* %28)
%30 = load i8*, i8** %5
%31 = load i64, i64* %6
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8 %29, i8* %32
br label %33
33: ; preds = %27
%34 = load i64, i64* %6
%35 = add i64 %34, 1
store i64 %35, i64* %6
br label %22
36: ; preds = %22
%37 = load i8*, i8** %5
%38 = load i64, i64* %6
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %5
%41 = load i8*, i8** %4
%42 = call i64 @strcmp(i8* %40, i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %36
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %4
%47 = load i8*, i8** %5
%48 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %46, i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %36
%51 = load i8*, i8** %5
%52 = call i32 @free(i8* %51)
br label %53
53: ; preds = %50, %10
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Expected \22%s\22, but got \22%s\22\0A\00"
define void @expect(i32* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %30, label %5
5: ; preds = %2
%6 = trunc i64 %3 to i32
%7 = add i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call signext i8 @read_char(i32* %0, i32 1)
store i8 %9, i8* %8
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = icmp ugt i64 %10, 1
br i1 %11, label %12, label %19
12: ; preds = %5, %12
%13 = phi i64 [ %16, %12 ], [ 1, %5 ]
%14 = tail call signext i8 @fgetc(i32* %0)
%15 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 %14, i8* %15
%16 = add nuw i64 %13, 1
%17 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%18 = icmp ult i64 %16, %17
br i1 %18, label %12, label %19
19: ; preds = %12, %5
%20 = phi i64 [ 1, %5 ], [ %16, %12 ]
%21 = getelementptr inbounds i8, i8* %8, i64 %20
store i8 0, i8* %21
%22 = tail call i64 @strcmp(i8* %8, i8* %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %8)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = tail call i32 @free(i8* %8)
br label %30
30: ; preds = %2, %28
ret void
}