#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*/ *fopen(char const *, char *);
int lzpt_read_toc(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int is_lzpt_file(const char *fname) {
  FILE *fh = NULL;
  int ret;
  if (!(fh = fopen(fname, "rb"))) {
    return 0;
  }
  ret = lzpt_read_toc(fh, NULL, NULL, NULL);
  fclose(fh);
  return (ret == 0);
}


x86 assembly (clang, -O0):
<is_lzpt_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    116e <is_lzpt_file+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    119c <is_lzpt_file+0x6c>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1040 <lzpt_read_toc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_lzpt_file>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1168 <is_lzpt_file+0x38>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <lzpt_read_toc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
jmp    116a <is_lzpt_file+0x3a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @is_lzpt_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32* null, i32** %4
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 0, i32* %2
br label %18
10: ; preds = %1
%11 = load i32*, i32** %4
%12 = call i32 @lzpt_read_toc(i32* %11, i32* null, i32* null, i32* null)
store i32 %12, i32* %5
%13 = load i32*, i32** %4
%14 = call i32 @fclose(i32* %13)
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
store i32 %17, i32* %2
br label %18
18: ; preds = %10, %9
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @is_lzpt_file(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i32 @lzpt_read_toc(i32* %2, i32* null, i32* null, i32* null)
%6 = tail call i32 @fclose(i32* %2)
%7 = icmp eq i32 %5, 0
%8 = zext i1 %7 to i32
br label %9
9: ; preds = %1, %4
%10 = phi i32 [ %8, %4 ], [ 0, %1 ]
ret i32 %10
}