#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 */
struct mpeg {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int mpeg_extract_info(unsigned long, struct mpeg *);
unsigned long mpeg_seek_nextheader(int /*<<< orphan*/ *);
int mpeg_read(const char *path, struct mpeg *mpeg) {
  FILE *fp;
  unsigned long int header;
  if ((fp = fopen(path, "rb")) == NULL) {
    return (-1);
  }
  if ((header = mpeg_seek_nextheader(fp)) == (unsigned long int)-1) {
    return (-1);
  }
  if (mpeg_extract_info(header, mpeg) == -1) {
    return (-1);
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<mpeg_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    117a <mpeg_read+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <mpeg_read+0x8f>
mov    -0x20(%rbp),%rdi
call   1040 <mpeg_seek_nextheader@plt>
mov    %rax,-0x28(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    119d <mpeg_read+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <mpeg_read+0x8f>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <mpeg_extract_info@plt>
cmp    $0xffffffff,%eax
jne    11bf <mpeg_read+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <mpeg_read+0x8f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpeg_read>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1188 <mpeg_read+0x48>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <mpeg_seek_nextheader@plt>
cmp    $0xffffffffffffffff,%rax
je     1188 <mpeg_read+0x48>
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <mpeg_extract_info@plt>
cmp    $0xffffffff,%eax
je     1188 <mpeg_read+0x48>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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