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

/* Variables and functions */
int REG_NOMATCH;
int /*<<< orphan*/ debug_write(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int log_readline(FILE *logfile, char *line, regex_t *regex) {
  int status = 0;
  int err;
  if (fgets(line, 16384, logfile) != NULL) {
    err = regexec(regex, line, 0, NULL, 0);
    if (err == REG_NOMATCH) {
      debug_write("Failed regex match\n");
      status = 1;
    }
    return status;
  }
  status = 2;
  return status;
}


x86 assembly (clang, -O0):
<log_readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x4000,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11b1 <log_readline+0x81>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1040 <regexec@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%eax
jne    11a6 <log_readline+0x76>
lea    0xe66(%rip),%rdi
call   1050 <debug_write@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <log_readline+0x8e>
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_readline>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rdx
mov    %rsi,%rdi
mov    $0x4000,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     1184 <log_readline+0x54>
xor    %r14d,%r14d
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <regexec@plt>
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%eax
jne    118a <log_readline+0x5a>
lea    0xe89(%rip),%rdi
call   1050 <debug_write@plt>
mov    $0x1,%r14d
jmp    118a <log_readline+0x5a>
mov    $0x2,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@REG_NOMATCH = global i32 0
@.str = [20 x i8] c"Failed regex match\0A\00"
define i32 @log_readline(i32* nocapture %0, i8* %1, i32* %2) {
%4 = tail call i32* @fgets(i8* %1, i32 16384, i32* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = tail call i32 @regexec(i32* %2, i8* %1, i32 0, i32* null, i32 0)
%8 = load i32, i32* @REG_NOMATCH
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @debug_write(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %3, %6, %10
%13 = phi i32 [ 1, %10 ], [ 0, %6 ], [ 2, %3 ]
ret i32 %13
}