#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 colog_use_line(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int colog_operation(char *mptr) {
  FILE *h;
  int status;
  char buffer[2048];
  if (!(h = fopen(mptr, "r")))
    return (40);
  else {
    while (fgets(buffer, 2048, h) > 0)
      if ((status = colog_use_line(buffer)) != 0)
        break;
    fclose(h);
    return (0);
  }
}


x86 assembly (clang, -O0):
<colog_operation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1179 <colog_operation+0x39>
movl   $0x28,-0x4(%rbp)
jmp    11cf <colog_operation+0x8f>
jmp    117e <colog_operation+0x3e>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x800,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jle    11bf <colog_operation+0x7f>
lea    -0x820(%rbp),%rdi
call   1050 <colog_use_line@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11ba <colog_operation+0x7a>
jmp    11bf <colog_operation+0x7f>
jmp    117e <colog_operation+0x3e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colog_operation>:
push   %r14
push   %rbx
sub    $0x808,%rsp
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <colog_operation+0x5d>
mov    %rax,%rbx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jle    1191 <colog_operation+0x51>
mov    %r14,%rdi
call   1050 <colog_use_line@plt>
test   %eax,%eax
je     1170 <colog_operation+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11a2 <colog_operation+0x62>
mov    $0x28,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @colog_operation(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [2048 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 40, i32* %2
br label %26
11: ; preds = %1
br label %12
12: ; preds = %22, %11
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i64 @fgets(i8* %13, i32 2048, i32* %14)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%19 = call i32 @colog_use_line(i8* %18)
store i32 %19, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
br label %23
22: ; preds = %17
br label %12
23: ; preds = %21, %12
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
store i32 0, i32* %2
br label %26
26: ; preds = %23, %10
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @colog_operation(i8* nocapture %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %14, label %6
6: ; preds = %1, %9
%7 = call i64 @fgets(i8* %3, i32 2048, i32* %4)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = call i32 @colog_use_line(i8* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %9, %6
%13 = call i32 @fclose(i32* %4)
br label %14
14: ; preds = %1, %12
%15 = phi i32 [ 0, %12 ], [ 40, %1 ]
ret i32 %15
}