#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memset(int *, int, int);
void fix_header(uint8_t *header_buffer) {
  header_buffer[7] = header_buffer[7] & 0xC0;
  int pts_dts_flag = (header_buffer[7] >> 6);
  int skip_size = 0;
  if (pts_dts_flag == 1) {
    header_buffer[7] = 0;
    pts_dts_flag = 0;
  }
  if (pts_dts_flag & 2)
    skip_size += 5;
  if (pts_dts_flag & 1)
    skip_size += 5;
  int clear_size = header_buffer[9] - skip_size;
  if (clear_size < 0) {
    header_buffer[7] = 0;
    skip_size = 0;
    clear_size = header_buffer[9];
  }
  if (clear_size == 0)
    return;
  memset(header_buffer + 9 + skip_size, 0xFF, clear_size);
}


x86 assembly (clang, -O0):
<fix_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x1c(%rax),%ecx
and    $0xc0,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    -0x8(%rbp),%rax
mov    0x1c(%rax),%eax
sar    $0x6,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1160 <fix_header+0x50>
mov    -0x8(%rbp),%rax
movl   $0x0,0x1c(%rax)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1178 <fix_header+0x68>
mov    -0x10(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1190 <fix_header+0x80>
mov    -0x10(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x24(%rax),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c3 <fix_header+0xb3>
mov    -0x8(%rbp),%rax
movl   $0x0,0x1c(%rax)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x24(%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11d2 <fix_header+0xc2>
jmp    11f2 <fix_header+0xe2>
mov    -0x8(%rbp),%rdi
add    $0x24,%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
mov    $0xff,%esi
call   1030 <memset@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fix_header>:
mov    $0xc0,%eax
and    0x1c(%rdi),%eax
mov    %eax,%ecx
shr    $0x6,%ecx
xor    %edx,%edx
cmp    $0x40,%eax
cmove  %edx,%eax
cmove  %edx,%ecx
mov    %eax,0x1c(%rdi)
mov    %ecx,%edx
shl    $0x1e,%edx
sar    $0x1f,%edx
and    $0x5,%edx
lea    0x5(%rdx),%eax
test   $0x1,%cl
cmove  %edx,%eax
mov    0x24(%rdi),%ecx
mov    %ecx,%edx
sub    %eax,%edx
js     1160 <fix_header+0x50>
test   %edx,%edx
je     116f <fix_header+0x5f>
add    $0x24,%rdi
mov    %eax,%eax
lea    (%rdi,%rax,4),%rdi
mov    $0xff,%esi
jmp    1030 <memset@plt>
movl   $0x0,0x1c(%rdi)
xor    %eax,%eax
mov    %ecx,%edx
test   %edx,%edx
jne    114c <fix_header+0x3c>
ret

LLVM IR (-O0):
define void @fix_header(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 7
%8 = load i32, i32* %7
%9 = and i32 %8, 192
%10 = load i32*, i32** %2
%11 = getelementptr inbounds i32, i32* %10, i64 7
store i32 %9, i32* %11
%12 = load i32*, i32** %2
%13 = getelementptr inbounds i32, i32* %12, i64 7
%14 = load i32, i32* %13
%15 = ashr i32 %14, 6
store i32 %15, i32* %3
store i32 0, i32* %4
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = load i32*, i32** %2
%20 = getelementptr inbounds i32, i32* %19, i64 7
store i32 0, i32* %20
store i32 0, i32* %3
br label %21
21: ; preds = %18, %1
%22 = load i32, i32* %3
%23 = and i32 %22, 2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 5
store i32 %27, i32* %4
br label %28
28: ; preds = %25, %21
%29 = load i32, i32* %3
%30 = and i32 %29, 1
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 5
store i32 %34, i32* %4
br label %35
35: ; preds = %32, %28
%36 = load i32*, i32** %2
%37 = getelementptr inbounds i32, i32* %36, i64 9
%38 = load i32, i32* %37
%39 = load i32, i32* %4
%40 = sub nsw i32 %38, %39
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %35
%44 = load i32*, i32** %2
%45 = getelementptr inbounds i32, i32* %44, i64 7
store i32 0, i32* %45
store i32 0, i32* %4
%46 = load i32*, i32** %2
%47 = getelementptr inbounds i32, i32* %46, i64 9
%48 = load i32, i32* %47
store i32 %48, i32* %5
br label %49
49: ; preds = %43, %35
%50 = load i32, i32* %5
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %49
br label %61
53: ; preds = %49
%54 = load i32*, i32** %2
%55 = getelementptr inbounds i32, i32* %54, i64 9
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = load i32, i32* %5
%60 = call i32 @memset(i32* %58, i32 255, i32 %59)
br label %61
61: ; preds = %53, %52
ret void
}

LLVM IR (-O2):
define void @fix_header(i32* %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 7
%3 = load i32, i32* %2
%4 = and i32 %3, 192
%5 = lshr exact i32 %4, 6
%6 = icmp eq i32 %4, 64
%7 = select i1 %6, i32 0, i32 %4
%8 = select i1 %6, i32 0, i32 %5
store i32 %7, i32* %2
%9 = and i32 %8, 2
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 0, i32 5
%12 = and i32 %8, 1
%13 = icmp eq i32 %12, 0
%14 = add nuw nsw i32 %11, 5
%15 = select i1 %13, i32 %11, i32 %14
%16 = getelementptr inbounds i32, i32* %0, i64 9
%17 = load i32, i32* %16
%18 = sub nsw i32 %17, %15
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %1
store i32 0, i32* %2
br label %21
21: ; preds = %20, %1
%22 = phi i32 [ 0, %20 ], [ %15, %1 ]
%23 = phi i32 [ %17, %20 ], [ %18, %1 ]
%24 = icmp eq i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = zext i32 %22 to i64
%27 = getelementptr inbounds i32, i32* %16, i64 %26
%28 = tail call i32 @memset(i32* %27, i32 255, i32 %23)
br label %29
29: ; preds = %21, %25
ret void
}