#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 BUFSIZ;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ feof(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
scalar_t__ match(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  char b[BUFSIZ];
  int matches = 0;
  if (argc == 1) {
    fprintf(stderr, "syntax: %s [pattern...]\n", argv[0]);
    return 2;
  }
  while (!feof(stdin)) {
    int i;
    if (fgets(b, BUFSIZ, stdin)) {
      for (i = 0; b[i] && b[i] != '\n'; i++)
        ;
      b[i] = '\0';
      for (i = 1; i < argc; i++) {
        if (match(argv[i], b)) {
          fprintf(stdout, "'%s' =~ '%s'\n", argv[i], b);
        }
      }
    }
  }
  return matches ? EXIT_SUCCESS : EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11c4 <main+0x84>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    1320 <main+0x1e0>
jmp    11c9 <main+0x89>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ec <main+0xac>
jmp    12ec <main+0x1ac>
mov    -0x38(%rbp),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     12e7 <main+0x1a7>
movl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     1247 <main+0x107>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1257 <main+0x117>
jmp    126a <main+0x12a>
jmp    125c <main+0x11c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1218 <main+0xd8>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e2 <main+0x1a2>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <match@plt>
cmp    $0x0,%rax
je     12cf <main+0x18f>
mov    -0x38(%rbp),%rcx
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rdx
mov    (%rax,%rdx,8),%rdx
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12d4 <main+0x194>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    127d <main+0x13d>
jmp    12e7 <main+0x1a7>
jmp    11c9 <main+0x89>
cmpl   $0x0,-0x24(%rbp)
je     1307 <main+0x1c7>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    1313 <main+0x1d3>
mov    0x2cba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %edi,-0x2c(%rbp)
cmp    $0x1,%edi
jne    1194 <main+0x54>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xe7a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%eax
jmp    11b1 <main+0x71>
mov    0x2e4d(%rip),%r13
mov    0x0(%r13),%edi
call   1050 <feof@plt>
test   %eax,%eax
je     11c0 <main+0x80>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    -0x2c(%rbp),%r14d
lea    0xe4e(%rip),%r12
jmp    11e4 <main+0xa4>
nopl   (%rax)
mov    0x2e11(%rip),%r13
mov    0x0(%r13),%edi
call   1050 <feof@plt>
test   %eax,%eax
jne    11a8 <main+0x68>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    0x0(%r13),%edx
mov    %rbx,%rdi
call   1030 <fgets@plt>
test   %rax,%rax
je     11d0 <main+0x90>
xor    %eax,%eax
movzbl (%rbx,%rax,1),%ecx
test   %cl,%cl
je     1220 <main+0xe0>
cmp    $0xa,%cl
je     1220 <main+0xe0>
add    $0x1,%rax
jmp    1200 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
cmpl   $0x2,-0x2c(%rbp)
jl     11d0 <main+0x90>
mov    $0x1,%r13d
jmp    1249 <main+0x109>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13
cmp    %r13,%r14
je     11d0 <main+0x90>
mov    (%r15,%r13,8),%rdi
mov    %rbx,%rsi
call   1060 <match@plt>
test   %rax,%rax
je     1240 <main+0x100>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
mov    (%r15,%r13,8),%rdx
mov    %r12,%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1240 <main+0x100>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"syntax: %s [pattern...]\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.1 = [14 x i8] c"'%s' =~ '%s'\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
store i32 0, i32* %8
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 2, i32* %3
store i32 1, i32* %9
br label %94
23: ; preds = %2
br label %24
24: ; preds = %84, %23
%25 = load i32, i32* @stdin
%26 = call i32 @feof(i32 %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br i1 %28, label %29, label %85
29: ; preds = %24
%30 = load i32, i32* @BUFSIZ
%31 = load i32, i32* @stdin
%32 = call i64 @fgets(i8* %14, i32 %30, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %84
34: ; preds = %29
store i32 0, i32* %10
br label %35
35: ; preds = %52, %34
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %14, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %35
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %14, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 10
br label %49
49: ; preds = %42, %35
%50 = phi i1 [ false, %35 ], [ %48, %42 ]
br i1 %50, label %51, label %55
51: ; preds = %49
br label %52
52: ; preds = %51
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %35
55: ; preds = %49
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %14, i64 %57
store i8 0, i8* %58
store i32 1, i32* %10
br label %59
59: ; preds = %80, %55
%60 = load i32, i32* %10
%61 = load i32, i32* %4
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %83
63: ; preds = %59
%64 = load i8**, i8*** %5
%65 = load i32, i32* %10
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = load i8*, i8** %67
%69 = call i64 @match(i8* %68, i8* %14)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %79
71: ; preds = %63
%72 = load i32, i32* @stdout
%73 = load i8**, i8*** %5
%74 = load i32, i32* %10
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8*, i8** %73, i64 %75
%77 = load i8*, i8** %76
%78 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %77, i8* %14)
br label %79
79: ; preds = %71, %63
br label %80
80: ; preds = %79
%81 = load i32, i32* %10
%82 = add nsw i32 %81, 1
store i32 %82, i32* %10
br label %59
83: ; preds = %59
br label %84
84: ; preds = %83, %29
br label %24
85: ; preds = %24
%86 = load i32, i32* %8
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %85
%89 = load i32, i32* @EXIT_SUCCESS
br label %92
90: ; preds = %85
%91 = load i32, i32* @EXIT_FAILURE
br label %92
92: ; preds = %90, %88
%93 = phi i32 [ %89, %88 ], [ %91, %90 ]
store i32 %93, i32* %3
store i32 1, i32* %9
br label %94
94: ; preds = %92, %17
%95 = load i8*, i8** %6
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"syntax: %s [pattern...]\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.1 = [14 x i8] c"'%s' =~ '%s'\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i32 %0, 1
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = load i32, i32* @stdin
%9 = call i32 @feof(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %49
11: ; preds = %7
%12 = icmp sgt i32 %0, 1
%13 = zext i32 %0 to i64
br label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %51
18: ; preds = %11, %45
%19 = load i32, i32* @BUFSIZ
%20 = load i32, i32* @stdin
%21 = call i64 @fgets(i8* %5, i32 %19, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %45, label %23
23: ; preds = %18, %27
%24 = phi i64 [ %28, %27 ], [ 0, %18 ]
%25 = getelementptr inbounds i8, i8* %5, i64 %24
%26 = load i8, i8* %25
switch i8 %26, label %27 [
i8 0, label %29
i8 10, label %29
]
27: ; preds = %23
%28 = add nuw i64 %24, 1
br label %23
29: ; preds = %23, %23
%30 = and i64 %24, 4294967295
%31 = getelementptr inbounds i8, i8* %5, i64 %30
store i8 0, i8* %31
br i1 %12, label %32, label %45
32: ; preds = %29, %42
%33 = phi i64 [ %43, %42 ], [ 1, %29 ]
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = call i64 @match(i8* %35, i8* %5)
%37 = icmp eq i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %32
%39 = load i32, i32* @stdout
%40 = load i8*, i8** %34
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %5)
br label %42
42: ; preds = %32, %38
%43 = add nuw nsw i64 %33, 1
%44 = icmp eq i64 %43, %13
br i1 %44, label %45, label %32
45: ; preds = %42, %29, %18
%46 = load i32, i32* @stdin
%47 = call i32 @feof(i32 %46)
%48 = icmp eq i32 %47, 0
br i1 %48, label %18, label %49
49: ; preds = %45, %7
%50 = load i32, i32* @EXIT_FAILURE
br label %51
51: ; preds = %49, %14
%52 = phi i32 [ 2, %14 ], [ %50, %49 ]
ret i32 %52
}