#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 */

/* Variables and functions */
int getchar();
int /*<<< orphan*/ putchar(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/);
int match(const char *ocp) {
  const char *cp;
  int c;
  for (cp = ocp + 1; *cp; cp++) {
    c = getchar();
    if (c != *cp) {
      while (ocp < cp)
        putchar(*ocp++);
      ungetc(c, stdin);
      return (0);
    }
  }
  return (1);
}


x86 assembly (clang, -O0):
<match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d3 <match+0xa3>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11bd <match+0x8d>
jmp    1176 <match+0x46>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a0 <match+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    1176 <match+0x46>
mov    -0x1c(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1050 <ungetc@plt>
movl   $0x0,-0x4(%rbp)
jmp    11da <match+0xaa>
jmp    11c2 <match+0x92>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1148 <match+0x18>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rdi,%rbx
nopl   (%rax)
cmpb   $0x0,0x1(%rbx)
je     1198 <match+0x68>
lea    0x1(%rbx),%rbp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%r15d
movsbl 0x1(%rbx),%eax
mov    %rbp,%rbx
cmp    %eax,%r15d
je     1140 <match+0x10>
cmp    %r14,%rbp
jbe    1183 <match+0x53>
add    $0xffffffffffffffff,%rbp
add    $0xffffffffffffffff,%r14
nopl   (%rax)
movsbl 0x1(%r14),%edi
add    $0x1,%r14
call   1030 <putchar@plt>
cmp    %rbp,%r14
jb     1170 <match+0x40>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1050 <ungetc@plt>
xor    %eax,%eax
jmp    119d <match+0x6d>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @match(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %7, i8** %4
br label %8
8: ; preds = %35, %1
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %38
12: ; preds = %8
%13 = call i32 (...) @getchar()
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %14, %17
br i1 %18, label %19, label %34
19: ; preds = %12
br label %20
20: ; preds = %24, %19
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = icmp ult i8* %21, %22
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
%27 = load i8, i8* %25
%28 = sext i8 %27 to i32
%29 = call i32 @putchar(i32 %28)
br label %20
30: ; preds = %20
%31 = load i32, i32* %5
%32 = load i32, i32* @stdin
%33 = call i32 @ungetc(i32 %31, i32 %32)
store i32 0, i32* %2
br label %39
34: ; preds = %12
br label %35
35: ; preds = %34
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
br label %8
38: ; preds = %8
store i32 1, i32* %2
br label %39
39: ; preds = %38, %30
%40 = load i32, i32* %2
ret i32 %40
}

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