#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 getc(int /*<<< orphan*/ *);
int tolower(unsigned char const);
int cmp_case(const char *key, FILE *fp) {
  const unsigned char *k = (unsigned char *)key;
  int c;
  while (*k != 0 && tolower(c = getc(fp)) == tolower(*k)) {
    k++;
  }
  return *k == 0 ? 0 : c == '\n' ? 1 : c == EOF ? -1 : tolower(*k) - tolower(c);
}


x86 assembly (clang, -O0):
<cmp_case>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     117d <cmp_case+0x5d>
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x1c(%rbp)
movzbl %al,%edi
call   1030 <tolower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    118d <cmp_case+0x6d>
jmp    119e <cmp_case+0x7e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <cmp_case+0x18>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    11b8 <cmp_case+0x98>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    121e <cmp_case+0xfe>
cmpl   $0xa,-0x1c(%rbp)
jne    11cf <cmp_case+0xaf>
mov    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1218 <cmp_case+0xf8>
mov    -0x1c(%rbp),%eax
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%eax
jne    11ee <cmp_case+0xce>
mov    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    1212 <cmp_case+0xf2>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
movzbl %al,%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_case>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r14d,%r14d
cmpb   $0x0,(%rdi)
je     11a9 <cmp_case+0x89>
mov    %rsi,%r15
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <getc@plt>
mov    %eax,%r12d
movzbl %r12b,%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movzbl (%rbx),%edi
call   1030 <tolower@plt>
cmp    %eax,%ebp
jne    116e <cmp_case+0x4e>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1140 <cmp_case+0x20>
jmp    11a9 <cmp_case+0x89>
mov    (%rbx),%al
test   %al,%al
je     11a9 <cmp_case+0x89>
mov    $0x1,%r14d
cmp    $0xa,%r12d
je     11a9 <cmp_case+0x89>
mov    0x2e61(%rip),%rcx
mov    $0xffffffff,%r14d
cmp    (%rcx),%r12d
je     11a9 <cmp_case+0x89>
movzbl %al,%edi
call   1030 <tolower@plt>
mov    %eax,%r14d
movzbl %r12b,%edi
call   1030 <tolower@plt>
sub    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @cmp_case(i8* nocapture %0, i32* nocapture %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %30, label %5
5: ; preds = %2, %13
%6 = phi i8* [ %14, %13 ], [ %0, %2 ]
%7 = tail call i32 @getc(i32* %1)
%8 = trunc i32 %7 to i8
%9 = tail call i32 @tolower(i8 zeroext %8)
%10 = load i8, i8* %6
%11 = tail call i32 @tolower(i8 zeroext %10)
%12 = icmp eq i32 %9, %11
br i1 %12, label %13, label %17
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %6, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %30, label %5
17: ; preds = %5
%18 = trunc i32 %7 to i8
%19 = load i8, i8* %6
%20 = icmp eq i8 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %17
%22 = icmp eq i32 %7, 10
br i1 %22, label %30, label %23
23: ; preds = %21
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %7, %24
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = tail call i32 @tolower(i8 zeroext %19)
%28 = tail call i32 @tolower(i8 zeroext %18)
%29 = sub nsw i32 %27, %28
br label %30
30: ; preds = %13, %2, %21, %23, %26, %17
%31 = phi i32 [ 0, %17 ], [ 1, %21 ], [ %29, %26 ], [ -1, %23 ], [ 0, %2 ], [ 0, %13 ]
ret i32 %31
}