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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ REG_EXTENDED;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regexc(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *fp;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  regex_t preg;
  regmatch_t match;
  fp = fopen("broadcast.smil", "r");
  if (fp == NULL)
    exit(EXIT_FAILURE);
  int err = regcomp(&preg, "(img|video) src=\"(.*)\" alt=\"(.*)\" dur=\"(.*)\"",
                    REG_EXTENDED);
  while ((read = getline(&line, &len, fp)) != -1) {
    printf("%s", line);
    regexc(&preg, line, 1, 0, match, 0);
  }
  if (line)
    free(line);
  regfree(&preg);
  return EXIT_SUCCESS;
}


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)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe53(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d6 <main+0x56>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1060 <regcomp@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     1240 <main+0xc0>
mov    -0x20(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%r8d
lea    -0x30(%rbp),%rdi
mov    $0x1,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
call   1070 <regexc@plt>
jmp    11f2 <main+0x72>
cmpq   $0x0,-0x20(%rbp)
je     1254 <main+0xd4>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    -0x30(%rbp),%rdi
call   1040 <regfree@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe5a(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1277 <main+0xf7>
mov    %rax,%rbx
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
lea    0xe43(%rip),%rsi
lea    0x14(%rsp),%rdi
call   1060 <regcomp@plt>
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     1247 <main+0xc7>
lea    0xe48(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x18(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r9d,%r9d
call   1070 <regexc@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
jne    1210 <main+0x90>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1256 <main+0xd6>
call   1030 <free@plt>
lea    0x14(%rsp),%rdi
call   1040 <regfree@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"broadcast.smil\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [45 x i8] c"(img|video) src=\22(.*)\22 alt=\22(.*)\22 dur=\22(.*)\22\00"
@REG_EXTENDED = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i64 0, i64* %8
%13 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32, i32* @REG_EXTENDED
%21 = call i32 @regcomp(i32* %10, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %20)
store i32 %21, i32* %12
br label %22
22: ; preds = %26, %19
%23 = load i32*, i32** %6
%24 = call i32 @getline(i8** %7, i64* %8, i32* %23)
store i32 %24, i32* %9
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i8*, i8** %7
%28 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %7
%30 = load i32, i32* %11
%31 = call i32 @regexc(i32* %10, i8* %29, i32 1, i32 0, i32 %30, i32 0)
br label %22
32: ; preds = %22
%33 = load i8*, i8** %7
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** %7
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %35, %32
%39 = call i32 @regfree(i32* %10)
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}

LLVM IR (-O2):
@.str = [15 x i8] c"broadcast.smil\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [45 x i8] c"(img|video) src=\22(.*)\22 alt=\22(.*)\22 dur=\22(.*)\22\00"
@REG_EXTENDED = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = bitcast i32* %5 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* @REG_EXTENDED
%16 = call i32 @regcomp(i32* %5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 @getline(i8** %3, i64* %4, i32* %9)
%18 = icmp eq i32 %17, -1
br i1 %18, label %26, label %19
19: ; preds = %14, %19
%20 = load i8*, i8** %3
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %3
%23 = call i32 @regexc(i32* %5, i8* %22, i32 1, i32 0, i32 undef, i32 0)
%24 = call i32 @getline(i8** %3, i64* %4, i32* %9)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %19
26: ; preds = %19, %14
%27 = load i8*, i8** %3
%28 = icmp eq i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 @free(i8* %27)
br label %31
31: ; preds = %29, %26
%32 = call i32 @regfree(i32* %5)
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}