#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ gw_parse_line(char *, char const *, char **);
char *strchr(char *, char);
int gw_parse_file(const char *file, const char *pattern, char **return_msg) {
  FILE *fd;
  char line[256], *pline;
  int found = 0;
  line[255] = '\0';
  fd = fopen(file, "r");
  *return_msg = NULL;
  if (fd == NULL)
    return -1;
  while (fgets(line, 255, fd) != NULL) {
    pline = strchr(line, '\n');
    if (pline != NULL)
      *pline = '\0';
    if (gw_parse_line(line, pattern, return_msg)) {
      found = 1;
      break;
    }
  }
  fclose(fd);
  return found;
}


x86 assembly (clang, -O0):
<gw_parse_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x13c(%rbp)
movb   $0x0,-0x31(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    11ab <gw_parse_file+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <gw_parse_file+0xf3>
jmp    11b0 <gw_parse_file+0x60>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1231 <gw_parse_file+0xe1>
lea    -0x130(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
je     11ff <gw_parse_file+0xaf>
mov    -0x138(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <gw_parse_line@plt>
cmp    $0x0,%rax
je     122c <gw_parse_file+0xdc>
movl   $0x1,-0x13c(%rbp)
jmp    1231 <gw_parse_file+0xe1>
jmp    11b0 <gw_parse_file+0x60>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x13c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gw_parse_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
movb   $0x0,0xff(%rsp)
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
movq   $0x0,(%r14)
test   %rax,%rax
je     11cf <gw_parse_file+0x7f>
mov    %rax,%r12
mov    %rsp,%rbx
jmp    11a3 <gw_parse_file+0x53>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <gw_parse_line@plt>
test   %rax,%rax
jne    11d6 <gw_parse_file+0x86>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11dd <gw_parse_file+0x8d>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1190 <gw_parse_file+0x40>
movb   $0x0,(%rax)
jmp    1190 <gw_parse_file+0x40>
mov    $0xffffffff,%ebx
jmp    11e7 <gw_parse_file+0x97>
mov    $0x1,%ebx
jmp    11df <gw_parse_file+0x8f>
xor    %ebx,%ebx
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @gw_parse_file(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca [256 x i8]
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i32 0, i32* %11
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 255
store i8 0, i8* %12
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %8
%15 = load i8**, i8*** %7
store i8* null, i8** %15
%16 = load i32*, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 -1, i32* %4
br label %44
19: ; preds = %3
br label %20
20: ; preds = %39, %19
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%22 = load i32*, i32** %8
%23 = call i32* @fgets(i8* %21, i32 255, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %40
25: ; preds = %20
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%27 = call i8* @strchr(i8* %26, i8 signext 10)
store i8* %27, i8** %10
%28 = load i8*, i8** %10
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = load i8*, i8** %10
store i8 0, i8* %31
br label %32
32: ; preds = %30, %25
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%34 = load i8*, i8** %6
%35 = load i8**, i8*** %7
%36 = call i64 @gw_parse_line(i8* %33, i8* %34, i8** %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %32
store i32 1, i32* %11
br label %40
39: ; preds = %32
br label %20
40: ; preds = %38, %20
%41 = load i32*, i32** %8
%42 = call i32 @fclose(i32* %41)
%43 = load i32, i32* %11
store i32 %43, i32* %4
br label %44
44: ; preds = %40, %18
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @gw_parse_file(i8* nocapture %0, i8* %1, i8** %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 255
store i8 0, i8* %6
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %22, label %9
9: ; preds = %3, %16
%10 = call i32* @fgets(i8* %5, i32 255, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %19, label %12
12: ; preds = %9
%13 = call i8* @strchr(i8* %5, i8 signext 10)
%14 = icmp eq i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12
store i8 0, i8* %13
br label %16
16: ; preds = %15, %12
%17 = call i64 @gw_parse_line(i8* %5, i8* %1, i8** %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %9, label %19
19: ; preds = %16, %9
%20 = phi i32 [ 0, %9 ], [ 1, %16 ]
%21 = call i32 @fclose(i32* %7)
br label %22
22: ; preds = %3, %19
%23 = phi i32 [ %20, %19 ], [ -1, %3 ]
ret i32 %23
}