#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*/ memcmp(unsigned char *, unsigned char const *, int);
int detailed_cvt_descriptor(unsigned char *x, int first) {
  const unsigned char empty[3] = {0, 0, 0};
  char *names[] = {"50", "60", "75", "85"};
  int width, height;
  int valid = 1;
  int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
  if (!first && !memcmp(x, empty, 3))
    return valid;
  height = x[0];
  height |= (x[1] & 0xf0) << 4;
  height++;
  height *= 2;
  switch (x[1] & 0x0c) {
  case 0x00:
    width = (height * 4) / 3;
    break;
  case 0x04:
    width = (height * 16) / 9;
    break;
  case 0x08:
    width = (height * 16) / 10;
    break;
  case 0x0c:
    width = (height * 15) / 9;
    break;
  }
  if (x[1] & 0x03)
    valid = 0;
  if (x[2] & 0x80)
    valid = 0;
  if (!(x[2] & 0x1f))
    valid = 0;
  fifty = (x[2] & 0x10);
  sixty = (x[2] & 0x08);
  seventyfive = (x[2] & 0x04);
  eightyfive = (x[2] & 0x02);
  reduced = (x[2] & 0x01);
  if (!valid) {
    (void)("    (broken)\n");
  } else {
    (void)("    %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\n", width, height,
           fifty ? "50 " : "", sixty ? "60 " : "", seventyfive ? "75 " : "",
           eightyfive ? "85 " : "", reduced ? "60RB " : "",
           names[(x[2] & 0x60) >> 5],
           (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
  }
  return valid;
}


x86 assembly (clang, -O0):
<detailed_cvt_descriptor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x17(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <memset@plt>
mov    0x2cba(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2cb7(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2cb4(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cb1(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11c5 <detailed_cvt_descriptor+0xa5>
mov    -0x10(%rbp),%rdi
lea    -0x17(%rbp),%rsi
mov    $0x3,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    11c5 <detailed_cvt_descriptor+0xa5>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1349 <detailed_cvt_descriptor+0x229>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%ecx
and    $0xfffffff0,%ecx
shl    $0x4,%ecx
mov    -0x48(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
add    %eax,%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xc,%eax
mov    %eax,%ecx
mov    %rcx,-0x68(%rbp)
sub    $0xc,%eax
ja     1275 <detailed_cvt_descriptor+0x155>
mov    -0x68(%rbp),%rax
lea    0xde5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x48(%rbp),%eax
shl    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
jmp    1275 <detailed_cvt_descriptor+0x155>
mov    -0x48(%rbp),%eax
shl    $0x4,%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
jmp    1275 <detailed_cvt_descriptor+0x155>
mov    -0x48(%rbp),%eax
shl    $0x4,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
jmp    1275 <detailed_cvt_descriptor+0x155>
imul   $0xf,-0x48(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     1290 <detailed_cvt_descriptor+0x170>
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     12ad <detailed_cvt_descriptor+0x18d>
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x1f,%eax
cmp    $0x0,%eax
jne    12c8 <detailed_cvt_descriptor+0x1a8>
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x10,%eax
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x8,%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x4,%eax
mov    %eax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x2,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x1,%eax
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    131d <detailed_cvt_descriptor+0x1fd>
jmp    1343 <detailed_cvt_descriptor+0x223>
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%ecx
and    $0x60,%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x69(%rbp)
jne    1340 <detailed_cvt_descriptor+0x220>
cmpl   $0x0,-0x60(%rbp)
setne  %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detailed_cvt_descriptor>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
test   %esi,%esi
jne    113e <detailed_cvt_descriptor+0x2e>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     1160 <detailed_cvt_descriptor+0x50>
testb  $0x3,0x1(%rbx)
sete   %al
mov    0x2(%rbx),%cl
test   %cl,%cl
setns  %dl
test   $0x1f,%cl
setne  %cl
and    %dl,%cl
and    %al,%cl
movzbl %cl,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x1,%eax
jmp    115a <detailed_cvt_descriptor+0x4a>

LLVM IR (-O0):
@.str = [3 x i8] c"50\00"
@.str.1 = [3 x i8] c"60\00"
@.str.2 = [3 x i8] c"75\00"
@.str.3 = [3 x i8] c"85\00"
@__const.detailed_cvt_descriptor.names = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [14 x i8] c" (broken)\0A\00"
@.str.5 = [47 x i8] c" %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\0A\00"
@.str.6 = [4 x i8] c"50 \00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [4 x i8] c"60 \00"
@.str.9 = [4 x i8] c"75 \00"
@.str.10 = [4 x i8] c"85 \00"
@.str.11 = [6 x i8] c"60RB \00"
@.str.12 = [3 x i8] c"RB\00"
define i32 @detailed_cvt_descriptor(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [3 x i8]
%7 = alloca [4 x i8*]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%16 = bitcast [3 x i8]* %6 to i8*
%17 = bitcast [4 x i8*]* %7 to i8*
store i32 1, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%23 = call i32 @memcmp(i8* %21, i8* %22, i32 3)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = load i32, i32* %10
store i32 %26, i32* %3
br label %165
27: ; preds = %20, %2
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
store i32 %31, i32* %9
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = and i32 %35, 240
%37 = shl i32 %36, 4
%38 = load i32, i32* %9
%39 = or i32 %38, %37
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = mul nsw i32 %42, 2
store i32 %43, i32* %9
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = and i32 %47, 12
switch i32 %48, label %65 [
i32 0, label %49
i32 4, label %53
i32 8, label %57
i32 12, label %61
]
49: ; preds = %27
%50 = load i32, i32* %9
%51 = mul nsw i32 %50, 4
%52 = sdiv i32 %51, 3
store i32 %52, i32* %8
br label %65
53: ; preds = %27
%54 = load i32, i32* %9
%55 = mul nsw i32 %54, 16
%56 = sdiv i32 %55, 9
store i32 %56, i32* %8
br label %65
57: ; preds = %27
%58 = load i32, i32* %9
%59 = mul nsw i32 %58, 16
%60 = sdiv i32 %59, 10
store i32 %60, i32* %8
br label %65
61: ; preds = %27
%62 = load i32, i32* %9
%63 = mul nsw i32 %62, 15
%64 = sdiv i32 %63, 9
store i32 %64, i32* %8
br label %65
65: ; preds = %27, %61, %57, %53, %49
%66 = load i8*, i8** %4
%67 = getelementptr inbounds i8, i8* %66, i64 1
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = and i32 %69, 3
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %65
store i32 0, i32* %10
br label %73
73: ; preds = %72, %65
%74 = load i8*, i8** %4
%75 = getelementptr inbounds i8, i8* %74, i64 2
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = and i32 %77, 128
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %73
store i32 0, i32* %10
br label %81
81: ; preds = %80, %73
%82 = load i8*, i8** %4
%83 = getelementptr inbounds i8, i8* %82, i64 2
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = and i32 %85, 31
%87 = icmp ne i32 %86, 0
br i1 %87, label %89, label %88
88: ; preds = %81
store i32 0, i32* %10
br label %89
89: ; preds = %88, %81
%90 = load i8*, i8** %4
%91 = getelementptr inbounds i8, i8* %90, i64 2
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = and i32 %93, 16
store i32 %94, i32* %11
%95 = load i8*, i8** %4
%96 = getelementptr inbounds i8, i8* %95, i64 2
%97 = load i8, i8* %96
%98 = zext i8 %97 to i32
%99 = and i32 %98, 8
store i32 %99, i32* %12
%100 = load i8*, i8** %4
%101 = getelementptr inbounds i8, i8* %100, i64 2
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = and i32 %103, 4
store i32 %104, i32* %13
%105 = load i8*, i8** %4
%106 = getelementptr inbounds i8, i8* %105, i64 2
%107 = load i8, i8* %106
%108 = zext i8 %107 to i32
%109 = and i32 %108, 2
store i32 %109, i32* %14
%110 = load i8*, i8** %4
%111 = getelementptr inbounds i8, i8* %110, i64 2
%112 = load i8, i8* %111
%113 = zext i8 %112 to i32
%114 = and i32 %113, 1
store i32 %114, i32* %15
%115 = load i32, i32* %10
%116 = icmp ne i32 %115, 0
br i1 %116, label %118, label %117
117: ; preds = %89
br label %163
118: ; preds = %89
%119 = load i32, i32* %8
%120 = load i32, i32* %9
%121 = load i32, i32* %11
%122 = icmp ne i32 %121, 0
%123 = zext i1 %122 to i64
%124 = select i1 %122, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%125 = load i32, i32* %12
%126 = icmp ne i32 %125, 0
%127 = zext i1 %126 to i64
%128 = select i1 %126, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%129 = load i32, i32* %13
%130 = icmp ne i32 %129, 0
%131 = zext i1 %130 to i64
%132 = select i1 %130, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%133 = load i32, i32* %14
%134 = icmp ne i32 %133, 0
%135 = zext i1 %134 to i64
%136 = select i1 %134, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%137 = load i32, i32* %15
%138 = icmp ne i32 %137, 0
%139 = zext i1 %138 to i64
%140 = select i1 %138, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%141 = load i8*, i8** %4
%142 = getelementptr inbounds i8, i8* %141, i64 2
%143 = load i8, i8* %142
%144 = zext i8 %143 to i32
%145 = and i32 %144, 96
%146 = ashr i32 %145, 5
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 %147
%149 = load i8*, i8** %148
%150 = load i8*, i8** %4
%151 = getelementptr inbounds i8, i8* %150, i64 2
%152 = load i8, i8* %151
%153 = zext i8 %152 to i32
%154 = and i32 %153, 96
%155 = icmp eq i32 %154, 32
br i1 %155, label %156, label %159
156: ; preds = %118
%157 = load i32, i32* %15
%158 = icmp ne i32 %157, 0
br label %159
159: ; preds = %156, %118
%160 = phi i1 [ false, %118 ], [ %158, %156 ]
%161 = zext i1 %160 to i64
%162 = select i1 %160, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
br label %163
163: ; preds = %159, %117
%164 = load i32, i32* %10
store i32 %164, i32* %3
br label %165
165: ; preds = %163, %25
%166 = load i32, i32* %3
ret i32 %166
}

LLVM IR (-O2):
define i32 @detailed_cvt_descriptor(i8* %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %1, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = call i32 @memcmp(i8* %0, i8* %4, i32 3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %6, %2
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = and i8 %11, 3
%13 = icmp eq i8 %12, 0
%14 = getelementptr inbounds i8, i8* %0, i64 2
%15 = load i8, i8* %14
%16 = icmp sgt i8 %15, -1
%17 = and i8 %15, 31
%18 = icmp ne i8 %17, 0
%19 = and i1 %16, %18
%20 = select i1 %19, i1 %13, i1 false
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %6, %9
%23 = phi i32 [ %21, %9 ], [ 1, %6 ]
ret i32 %23
}