#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
bool read_string(FILE *f, const char *s) {
  while (*s != '\0') {
    int c = fgetc(f);
    if (c == EOF || c != *s) {
      ungetc(c, f);
      return false;
    }
    s++;
  }
  return true;
}


x86 assembly (clang, -O0):
<read_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1199 <read_string+0x79>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%eax
je     1170 <read_string+0x50>
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1188 <read_string+0x68>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <ungetc@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <read_string+0x80>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1130 <read_string+0x10>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%r14d
cmpb   $0x0,(%rsi)
je     117e <read_string+0x5e>
mov    %rsi,%rbp
mov    %rdi,%rbx
add    $0x1,%rbp
mov    0x2ea5(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r15),%eax
je     1171 <read_string+0x51>
movsbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jne    1171 <read_string+0x51>
cmpb   $0x0,0x0(%rbp)
lea    0x1(%rbp),%rbp
jne    1150 <read_string+0x30>
jmp    117e <read_string+0x5e>
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <ungetc@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @read_string(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
br label %7
7: ; preds = %28, %2
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %7
%13 = load i32*, i32** %4
%14 = call i32 @fgetc(i32* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %24, label %18
18: ; preds = %12
%19 = load i32, i32* %6
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %19, %22
br i1 %23, label %24, label %28
24: ; preds = %18, %12
%25 = load i32, i32* %6
%26 = load i32*, i32** %4
%27 = call i32 @ungetc(i32 %25, i32* %26)
store i32 0, i32* %3
br label %32
28: ; preds = %18
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
br label %7
31: ; preds = %7
store i32 1, i32* %3
br label %32
32: ; preds = %31, %24
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @read_string(i32* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %20, label %8
5: ; preds = %13
%6 = load i8, i8* %17
%7 = icmp eq i8 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %2, %5
%9 = phi i8* [ %17, %5 ], [ %1, %2 ]
%10 = tail call i32 @fgetc(i32* %0)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = load i8, i8* %9
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %10, %15
%17 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %16, label %5, label %18
18: ; preds = %8, %13
%19 = tail call i32 @ungetc(i32 %10, i32* %0)
br label %20
20: ; preds = %5, %2, %18
%21 = phi i32 [ 0, %18 ], [ 1, %2 ], [ 1, %5 ]
ret i32 %21
}