#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ help();
char *malloc(int);
scalar_t__ match(char *, char *, int, char *);
int parse_string(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char *argv[]) {
  char *prefix;
  char *buf;
  int len;
  int i;
  int result;
  if (argc < 3) {
    help();
    return EXIT_FAILURE;
  }
  len = strlen(argv[1]);
  if (len == 0) {
    fprintf(stderr, "empty string\n");
    return EXIT_FAILURE;
  }
  prefix = malloc(len + 1);
  if (prefix == NULL) {
    fprintf(stderr, "can't allocate %d byte(s)\n", len + 1);
    return EXIT_FAILURE;
  }
  len = parse_string(argv[1], prefix);
  buf = malloc(len);
  if (buf == NULL) {
    free(prefix);
    fprintf(stderr, "can't allocate %d byte(s)\n", len);
    return EXIT_FAILURE;
  }
  errno = 0;
  if (argc == 3) {
    result = match(argv[2], prefix, len, buf) ? EXIT_SUCCESS : EXIT_FAILURE;
  } else
    for (i = 2; i < argc; i++) {
      result = EXIT_SUCCESS;
      if (match(argv[i], prefix, len, buf))
        puts(argv[i]);
    }
  free(buf);
  free(prefix);
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b8 <main+0x38>
mov    $0x0,%al
call   10a0 <help@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1389 <main+0x209>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11fa <main+0x7a>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1389 <main+0x209>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1242 <main+0xc2>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1389 <main+0x209>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <parse_string@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12a1 <main+0x121>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1389 <main+0x209>
mov    0x2d30(%rip),%rax
movq   $0x0,(%rax)
cmpl   $0x3,-0x8(%rbp)
jne    1303 <main+0x183>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1090 <match@plt>
cmp    $0x0,%rax
je     12ec <main+0x16c>
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    12f8 <main+0x178>
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1371 <main+0x1f1>
movl   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    136c <main+0x1ec>
mov    0x2cab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1090 <match@plt>
cmp    $0x0,%rax
je     1359 <main+0x1d9>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <puts@plt>
jmp    135e <main+0x1de>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    130a <main+0x18a>
jmp    1371 <main+0x1f1>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     119c <main+0x1c>
xor    %eax,%eax
call   10a0 <help@plt>
jmp    1271 <main+0xf1>
mov    %rsi,%rbx
mov    %edi,%r13d
mov    0x8(%rsi),%rdi
call   1060 <strlen@plt>
test   %eax,%eax
je     1222 <main+0xa2>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     123b <main+0xbb>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
mov    %rax,%rsi
call   1030 <parse_string@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     124f <main+0xcf>
mov    0x2def(%rip),%rax
movq   $0x0,(%rax)
cmp    $0x3,%r13d
jne    128b <main+0x10b>
mov    0x10(%rbx),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    (%rsp),%rcx
call   1090 <match@plt>
test   %rax,%rax
jne    12d5 <main+0x155>
mov    0x2db3(%rip),%rax
jmp    12dc <main+0x15c>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1271 <main+0xf1>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
mov    %ebp,%edx
jmp    126a <main+0xea>
mov    %r15,%rdi
call   1040 <free@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13d,%r13d
mov    $0x2,%r14d
jmp    12a9 <main+0x129>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r14,%r13
je     12de <main+0x15e>
mov    0x2d18(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx,%r14,8),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    (%rsp),%rcx
call   1090 <match@plt>
test   %rax,%rax
je     12a0 <main+0x120>
mov    (%rbx,%r14,8),%rdi
call   1050 <puts@plt>
jmp    12a0 <main+0x120>
mov    0x2cec(%rip),%rax
mov    (%rax),%ebp
mov    (%rsp),%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
jmp    127a <main+0xfa>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"empty string\0A\00"
@.str.1 = [27 x i8] c"can't allocate %d byte(s)\0A\00"
@errno = global i64 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%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* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (...) @help()
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %109
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %109
27: ; preds = %16
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
%30 = call i8* @malloc(i32 %29)
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %39
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %3
br label %109
39: ; preds = %27
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = load i8*, i8** %6
%44 = call i32 @parse_string(i8* %42, i8* %43)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = call i8* @malloc(i32 %45)
store i8* %46, i8** %7
%47 = load i8*, i8** %7
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %56
49: ; preds = %39
%50 = load i8*, i8** %6
%51 = call i32 @free(i8* %50)
%52 = load i32, i32* @stderr
%53 = load i32, i32* %8
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = load i32, i32* @EXIT_FAILURE
store i32 %55, i32* %3
br label %109
56: ; preds = %39
store i64 0, i64* @errno
%57 = load i32, i32* %4
%58 = icmp eq i32 %57, 3
br i1 %58, label %59, label %74
59: ; preds = %56
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 2
%62 = load i8*, i8** %61
%63 = load i8*, i8** %6
%64 = load i32, i32* %8
%65 = load i8*, i8** %7
%66 = call i64 @match(i8* %62, i8* %63, i32 %64, i8* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %59
%69 = load i32, i32* @EXIT_SUCCESS
br label %72
70: ; preds = %59
%71 = load i32, i32* @EXIT_FAILURE
br label %72
72: ; preds = %70, %68
%73 = phi i32 [ %69, %68 ], [ %71, %70 ]
store i32 %73, i32* %10
br label %103
74: ; preds = %56
store i32 2, i32* %9
br label %75
75: ; preds = %99, %74
%76 = load i32, i32* %9
%77 = load i32, i32* %4
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %102
79: ; preds = %75
%80 = load i32, i32* @EXIT_SUCCESS
store i32 %80, i32* %10
%81 = load i8**, i8*** %5
%82 = load i32, i32* %9
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8*, i8** %81, i64 %83
%85 = load i8*, i8** %84
%86 = load i8*, i8** %6
%87 = load i32, i32* %8
%88 = load i8*, i8** %7
%89 = call i64 @match(i8* %85, i8* %86, i32 %87, i8* %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %98
91: ; preds = %79
%92 = load i8**, i8*** %5
%93 = load i32, i32* %9
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8*, i8** %92, i64 %94
%96 = load i8*, i8** %95
%97 = call i32 @puts(i8* %96)
br label %98
98: ; preds = %91, %79
br label %99
99: ; preds = %98
%100 = load i32, i32* %9
%101 = add nsw i32 %100, 1
store i32 %101, i32* %9
br label %75
102: ; preds = %75
br label %103
103: ; preds = %102, %72
%104 = load i8*, i8** %7
%105 = call i32 @free(i8* %104)
%106 = load i8*, i8** %6
%107 = call i32 @free(i8* %106)
%108 = load i32, i32* %10
store i32 %108, i32* %3
br label %109
109: ; preds = %103, %49, %33, %23, %13
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"empty string\0A\00"
@.str.1 = [27 x i8] c"can't allocate %d byte(s)\0A\00"
@errno = global i64 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 (...) @help()
%6 = load i32, i32* @EXIT_FAILURE
br label %63
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
br label %63
16: ; preds = %7
%17 = add nsw i32 %10, 1
%18 = tail call i8* @malloc(i32 %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%23 = load i32, i32* @EXIT_FAILURE
br label %63
24: ; preds = %16
%25 = load i8*, i8** %8
%26 = tail call i32 @parse_string(i8* %25, i8* %18)
%27 = tail call i8* @malloc(i32 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = tail call i32 @free(i8* %18)
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%33 = load i32, i32* @EXIT_FAILURE
br label %63
34: ; preds = %24
store i64 0, i64* @errno
%35 = icmp eq i32 %0, 3
br i1 %35, label %38, label %36
36: ; preds = %34
%37 = zext i32 %0 to i64
br label %46
38: ; preds = %34
%39 = getelementptr inbounds i8*, i8** %1, i64 2
%40 = load i8*, i8** %39
%41 = tail call i64 @match(i8* %40, i8* %18, i32 %26, i8* %27)
%42 = icmp eq i64 %41, 0
%43 = load i32, i32* @EXIT_SUCCESS
%44 = load i32, i32* @EXIT_FAILURE
%45 = select i1 %42, i32 %44, i32 %43
br label %59
46: ; preds = %36, %56
%47 = phi i64 [ 2, %36 ], [ %57, %56 ]
%48 = load i32, i32* @EXIT_SUCCESS
%49 = getelementptr inbounds i8*, i8** %1, i64 %47
%50 = load i8*, i8** %49
%51 = tail call i64 @match(i8* %50, i8* %18, i32 %26, i8* %27)
%52 = icmp eq i64 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %46
%54 = load i8*, i8** %49
%55 = tail call i32 @puts(i8* dereferenceable(1) %54)
br label %56
56: ; preds = %46, %53
%57 = add nuw nsw i64 %47, 1
%58 = icmp eq i64 %57, %37
br i1 %58, label %59, label %46
59: ; preds = %56, %38
%60 = phi i32 [ %45, %38 ], [ %48, %56 ]
%61 = tail call i32 @free(i8* %27)
%62 = tail call i32 @free(i8* %18)
br label %63
63: ; preds = %59, %29, %20, %12, %4
%64 = phi i32 [ %6, %4 ], [ %15, %12 ], [ %23, %20 ], [ %33, %29 ], [ %60, %59 ]
ret i32 %64
}