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

/* Variables and functions */
int /*<<< orphan*/ write_edid_byte(unsigned char *, int, int);
void _filter_edid(unsigned char *edid, size_t edid_size, int analog_port) {
  int i;
  if (analog_port && (edid[20] & 0x80)) {
    write_edid_byte(edid, 20, 0x00);
    write_edid_byte(edid, 24, (edid[24] & 0xE7) | 0x08);
  } else if (!analog_port && !(edid[20] & 0x80)) {
    write_edid_byte(edid, 20, 0x80);
    write_edid_byte(edid, 24, (edid[24] & 0xE7));
  }
  write_edid_byte(edid, 24, edid[24] & 0x1F);
  for (i = 0; i < 4; i++) {
    unsigned char *timingDescriptor = (unsigned char *)&edid[54 + (18 * i)];
    unsigned short clock = timingDescriptor[0] + (timingDescriptor[1] << 8);
    if (clock > 16000) {
      write_edid_byte(edid, (&timingDescriptor[0] - edid), 16000 & 0xff);
      write_edid_byte(edid, (&timingDescriptor[1] - edid), 16000 >> 8);
    }
  }
}


x86 assembly (clang, -O0):
<_filter_edid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1177 <_filter_edid+0x67>
mov    -0x8(%rbp),%rax
movzbl 0x14(%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1177 <_filter_edid+0x67>
mov    -0x8(%rbp),%rdi
mov    $0x14,%esi
xor    %edx,%edx
call   1030 <write_edid_byte@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
movzbl 0x18(%rax),%edx
and    $0xe7,%edx
or     $0x8,%edx
mov    $0x18,%esi
call   1030 <write_edid_byte@plt>
jmp    11cb <_filter_edid+0xbb>
cmpl   $0x0,-0x14(%rbp)
jne    11c6 <_filter_edid+0xb6>
mov    -0x8(%rbp),%rax
movzbl 0x14(%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    11c6 <_filter_edid+0xb6>
mov    -0x8(%rbp),%rdi
mov    $0x14,%esi
mov    $0x80,%edx
call   1030 <write_edid_byte@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
movzbl 0x18(%rax),%edx
and    $0xe7,%edx
mov    $0x18,%esi
call   1030 <write_edid_byte@plt>
jmp    11cb <_filter_edid+0xbb>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
movzbl 0x18(%rax),%edx
and    $0x1f,%edx
mov    $0x18,%esi
call   1030 <write_edid_byte@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    127e <_filter_edid+0x16e>
mov    -0x8(%rbp),%rax
imul   $0x12,-0x18(%rbp),%ecx
add    $0x36,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
mov    -0x20(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %ax,-0x22(%rbp)
movzwl -0x22(%rbp),%eax
cmp    $0x3e80,%eax
jle    126b <_filter_edid+0x15b>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    $0x80,%edx
call   1030 <write_edid_byte@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    $0x3e,%edx
call   1030 <write_edid_byte@plt>
jmp    1270 <_filter_edid+0x160>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11eb <_filter_edid+0xdb>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_filter_edid>:
push   %rbx
mov    %rdi,%rbx
mov    0x14(%rdi),%al
test   %edx,%edx
je     1137 <_filter_edid+0x27>
test   %al,%al
jns    1162 <_filter_edid+0x52>
mov    %rbx,%rdi
mov    $0x14,%esi
xor    %edx,%edx
call   1030 <write_edid_byte@plt>
mov    0x18(%rbx),%al
and    $0xe7,%al
or     $0x8,%al
jmp    1152 <_filter_edid+0x42>
test   %al,%al
js     1162 <_filter_edid+0x52>
mov    %rbx,%rdi
mov    $0x14,%esi
mov    $0x80,%edx
call   1030 <write_edid_byte@plt>
mov    0x18(%rbx),%al
and    $0xe7,%al
movzbl %al,%edx
mov    %rbx,%rdi
mov    $0x18,%esi
call   1030 <write_edid_byte@plt>
movzbl 0x18(%rbx),%edx
and    $0x1f,%edx
mov    %rbx,%rdi
mov    $0x18,%esi
call   1030 <write_edid_byte@plt>
movzwl 0x36(%rbx),%eax
cmp    $0x3e81,%eax
jb     11a5 <_filter_edid+0x95>
mov    %rbx,%rdi
mov    $0x36,%esi
mov    $0x80,%edx
call   1030 <write_edid_byte@plt>
mov    %rbx,%rdi
mov    $0x37,%esi
mov    $0x3e,%edx
call   1030 <write_edid_byte@plt>
movzwl 0x48(%rbx),%eax
cmp    $0x3e81,%eax
jb     11d4 <_filter_edid+0xc4>
mov    %rbx,%rdi
mov    $0x48,%esi
mov    $0x80,%edx
call   1030 <write_edid_byte@plt>
mov    %rbx,%rdi
mov    $0x49,%esi
mov    $0x3e,%edx
call   1030 <write_edid_byte@plt>
movzwl 0x5a(%rbx),%eax
cmp    $0x3e81,%eax
jb     1203 <_filter_edid+0xf3>
mov    %rbx,%rdi
mov    $0x5a,%esi
mov    $0x80,%edx
call   1030 <write_edid_byte@plt>
mov    %rbx,%rdi
mov    $0x5b,%esi
mov    $0x3e,%edx
call   1030 <write_edid_byte@plt>
movzwl 0x6c(%rbx),%eax
cmp    $0x3e81,%eax
jb     1233 <_filter_edid+0x123>
mov    %rbx,%rdi
mov    $0x6c,%esi
mov    $0x80,%edx
call   1030 <write_edid_byte@plt>
mov    %rbx,%rdi
mov    $0x6d,%esi
mov    $0x3e,%edx
pop    %rbx
jmp    1030 <write_edid_byte@plt>
pop    %rbx
ret

LLVM IR (-O0):
define void @_filter_edid(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i16
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 20
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = and i32 %16, 128
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = call i32 @write_edid_byte(i8* %20, i32 20, i32 0)
%22 = load i8*, i8** %4
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 24
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = and i32 %26, 231
%28 = or i32 %27, 8
%29 = call i32 @write_edid_byte(i8* %22, i32 24, i32 %28)
br label %51
30: ; preds = %12, %3
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %50, label %33
33: ; preds = %30
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 20
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = and i32 %37, 128
%39 = icmp ne i32 %38, 0
br i1 %39, label %50, label %40
40: ; preds = %33
%41 = load i8*, i8** %4
%42 = call i32 @write_edid_byte(i8* %41, i32 20, i32 128)
%43 = load i8*, i8** %4
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 24
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = and i32 %47, 231
%49 = call i32 @write_edid_byte(i8* %43, i32 24, i32 %48)
br label %50
50: ; preds = %40, %33, %30
br label %51
51: ; preds = %50, %19
%52 = load i8*, i8** %4
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i64 24
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = and i32 %56, 31
%58 = call i32 @write_edid_byte(i8* %52, i32 24, i32 %57)
store i32 0, i32* %7
br label %59
59: ; preds = %103, %51
%60 = load i32, i32* %7
%61 = icmp slt i32 %60, 4
br i1 %61, label %62, label %106
62: ; preds = %59
%63 = load i8*, i8** %4
%64 = load i32, i32* %7
%65 = mul nsw i32 18, %64
%66 = add nsw i32 54, %65
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %63, i64 %67
store i8* %68, i8** %8
%69 = load i8*, i8** %8
%70 = getelementptr inbounds i8, i8* %69, i64 0
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = load i8*, i8** %8
%74 = getelementptr inbounds i8, i8* %73, i64 1
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = shl i32 %76, 8
%78 = add nsw i32 %72, %77
%79 = trunc i32 %78 to i16
store i16 %79, i16* %9
%80 = load i16, i16* %9
%81 = zext i16 %80 to i32
%82 = icmp sgt i32 %81, 16000
br i1 %82, label %83, label %102
83: ; preds = %62
%84 = load i8*, i8** %4
%85 = load i8*, i8** %8
%86 = getelementptr inbounds i8, i8* %85, i64 0
%87 = load i8*, i8** %4
%88 = ptrtoint i8* %86 to i64
%89 = ptrtoint i8* %87 to i64
%90 = sub i64 %88, %89
%91 = trunc i64 %90 to i32
%92 = call i32 @write_edid_byte(i8* %84, i32 %91, i32 128)
%93 = load i8*, i8** %4
%94 = load i8*, i8** %8
%95 = getelementptr inbounds i8, i8* %94, i64 1
%96 = load i8*, i8** %4
%97 = ptrtoint i8* %95 to i64
%98 = ptrtoint i8* %96 to i64
%99 = sub i64 %97, %98
%100 = trunc i64 %99 to i32
%101 = call i32 @write_edid_byte(i8* %93, i32 %100, i32 62)
br label %102
102: ; preds = %83, %62
br label %103
103: ; preds = %102
%104 = load i32, i32* %7
%105 = add nsw i32 %104, 1
store i32 %105, i32* %7
br label %59
106: ; preds = %59
ret void
}

LLVM IR (-O2):
define void @_filter_edid(i8* %0, i64 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
%5 = getelementptr inbounds i8, i8* %0, i64 20
%6 = load i8, i8* %5
%7 = icmp sgt i8 %6, -1
br i1 %4, label %15, label %8
8: ; preds = %3
br i1 %7, label %25, label %9
9: ; preds = %8
%10 = tail call i32 @write_edid_byte(i8* %0, i32 20, i32 0)
%11 = getelementptr inbounds i8, i8* %0, i64 24
%12 = load i8, i8* %11
%13 = and i8 %12, -25
%14 = or i8 %13, 8
br label %21
15: ; preds = %3
br i1 %7, label %16, label %25
16: ; preds = %15
%17 = tail call i32 @write_edid_byte(i8* %0, i32 20, i32 128)
%18 = getelementptr inbounds i8, i8* %0, i64 24
%19 = load i8, i8* %18
%20 = and i8 %19, -25
br label %21
21: ; preds = %9, %16
%22 = phi i8 [ %20, %16 ], [ %14, %9 ]
%23 = zext i8 %22 to i32
%24 = tail call i32 @write_edid_byte(i8* %0, i32 24, i32 %23)
br label %25
25: ; preds = %21, %8, %15
%26 = getelementptr inbounds i8, i8* %0, i64 24
%27 = load i8, i8* %26
%28 = and i8 %27, 31
%29 = zext i8 %28 to i32
%30 = tail call i32 @write_edid_byte(i8* %0, i32 24, i32 %29)
%31 = getelementptr inbounds i8, i8* %0, i64 54
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = getelementptr inbounds i8, i8* %0, i64 55
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = shl nuw nsw i32 %36, 8
%38 = or i32 %37, %33
%39 = icmp ugt i32 %38, 16000
br i1 %39, label %40, label %43
40: ; preds = %25
%41 = tail call i32 @write_edid_byte(i8* %0, i32 54, i32 128)
%42 = tail call i32 @write_edid_byte(i8* %0, i32 55, i32 62)
br label %43
43: ; preds = %40, %25
%44 = getelementptr inbounds i8, i8* %0, i64 72
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = getelementptr inbounds i8, i8* %0, i64 73
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = shl nuw nsw i32 %49, 8
%51 = or i32 %50, %46
%52 = icmp ugt i32 %51, 16000
br i1 %52, label %53, label %56
53: ; preds = %43
%54 = tail call i32 @write_edid_byte(i8* %0, i32 72, i32 128)
%55 = tail call i32 @write_edid_byte(i8* %0, i32 73, i32 62)
br label %56
56: ; preds = %53, %43
%57 = getelementptr inbounds i8, i8* %0, i64 90
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = getelementptr inbounds i8, i8* %0, i64 91
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = shl nuw nsw i32 %62, 8
%64 = or i32 %63, %59
%65 = icmp ugt i32 %64, 16000
br i1 %65, label %66, label %69
66: ; preds = %56
%67 = tail call i32 @write_edid_byte(i8* %0, i32 90, i32 128)
%68 = tail call i32 @write_edid_byte(i8* %0, i32 91, i32 62)
br label %69
69: ; preds = %66, %56
%70 = getelementptr inbounds i8, i8* %0, i64 108
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = getelementptr inbounds i8, i8* %0, i64 109
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = shl nuw nsw i32 %75, 8
%77 = or i32 %76, %72
%78 = icmp ugt i32 %77, 16000
br i1 %78, label %79, label %82
79: ; preds = %69
%80 = tail call i32 @write_edid_byte(i8* %0, i32 108, i32 128)
%81 = tail call i32 @write_edid_byte(i8* %0, i32 109, i32 62)
br label %82
82: ; preds = %79, %69
ret void
}