#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*/ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int begin(regex_t *reg) {
  regmatch_t result;
  char line[1024];
  char *ptr;
  while (NULL != (ptr = fgets(line, 1024, stdin)))
    if (0 == regexec(reg, line, 1, &result, 0))
      break;
  if (ptr) {
    printf("%s", ptr);
    while (NULL != fgets(line, 1024, stdin))
      printf("%s", line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<begin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
mov    %rcx,-0x418(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     11a2 <begin+0x72>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    $0x1,%edx
lea    -0xc(%rbp),%rcx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    119d <begin+0x6d>
jmp    11a2 <begin+0x72>
jmp    113f <begin+0xf>
cmpq   $0x0,-0x418(%rbp)
je     1208 <begin+0xd8>
mov    -0x418(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1203 <begin+0xd3>
lea    -0x410(%rbp),%rsi
lea    0xe07(%rip),%rdi
call   1030 <printf@plt>
jmp    11c3 <begin+0x93>
jmp    1208 <begin+0xd8>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<begin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %rdi,%r14
mov    0x2e9e(%rip),%r13
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11f1 <begin+0xc1>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1050 <regexec@plt>
test   %rax,%rax
jne    1160 <begin+0x30>
lea    0xe65(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x0(%r13),%edx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11f1 <begin+0xc1>
lea    0xe3e(%rip),%r14
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
jne    11d0 <begin+0xa0>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @begin(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i8*
store i32* %0, i32** %2
br label %6
6: ; preds = %17, %1
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i8* @fgets(i8* %7, i32 1024, i32 %8)
store i8* %9, i8** %5
%10 = icmp ne i8* null, %9
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = load i32*, i32** %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i64 @regexec(i32* %12, i8* %13, i32 1, i32* %3, i32 0)
%15 = icmp eq i64 0, %14
br i1 %15, label %16, label %17
16: ; preds = %11
br label %18
17: ; preds = %11
br label %6
18: ; preds = %16, %6
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = load i8*, i8** %5
%23 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %29, %21
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%26 = load i32, i32* @stdin
%27 = call i8* @fgets(i8* %25, i32 1024, i32 %26)
%28 = icmp ne i8* null, %27
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %30)
br label %24
32: ; preds = %24
br label %33
33: ; preds = %32, %18
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @begin(i32* %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %10, %1
%7 = load i32, i32* @stdin
%8 = call i8* @fgets(i8* %5, i32 1024, i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %23, label %10
10: ; preds = %6
%11 = call i64 @regexec(i32* %0, i8* %5, i32 1, i32* %2, i32 0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %6
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%15 = load i32, i32* @stdin
%16 = call i8* @fgets(i8* %5, i32 1024, i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %23, label %18
18: ; preds = %13, %18
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%20 = load i32, i32* @stdin
%21 = call i8* @fgets(i8* %5, i32 1024, i32 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %18
23: ; preds = %6, %18, %13
ret i32 0
}