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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
void i830_debug_vga_pd(char *result, int len, int reg, uint32_t val,
                       uint32_t devid) {
  int vga0_p1, vga0_p2, vga1_p1, vga1_p2;
  if (val & (1 << 5))
    vga0_p1 = 2;
  else
    vga0_p1 = ((val & (0x1f << 0)) >> 0) + 2;
  vga0_p2 = (val & (1 << 7)) ? 4 : 2;
  if (val & (1 << 13))
    vga1_p1 = 2;
  else
    vga1_p1 = ((val & (0x1f << 8)) >> 8) + 2;
  vga1_p2 = (val & (1 << 15)) ? 4 : 2;
  snprintf(result, len, "vga0 p1 = %d, p2 = %d, vga1 p1 = %d, p2 = %d", vga0_p1,
           vga0_p2, vga1_p1, vga1_p2);
}


x86 assembly (clang, -O0):
<i830_debug_vga_pd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1144 <i830_debug_vga_pd+0x34>
movl   $0x2,-0x1c(%rbp)
jmp    1153 <i830_debug_vga_pd+0x43>
mov    -0x14(%rbp),%eax
and    $0x1f,%eax
sar    $0x0,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edx
and    $0x80,%edx
mov    $0x2,%eax
mov    $0x4,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
and    $0x2000,%eax
cmp    $0x0,%eax
je     118c <i830_debug_vga_pd+0x7c>
movl   $0x2,-0x24(%rbp)
jmp    119d <i830_debug_vga_pd+0x8d>
mov    -0x14(%rbp),%eax
and    $0x1f00,%eax
sar    $0x8,%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edx
and    $0x8000,%edx
mov    $0x2,%eax
mov    $0x4,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    -0x28(%rbp),%eax
lea    0xe2b(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i830_debug_vga_pd>:
push   %rax
mov    %ecx,%eax
and    $0x1f,%ecx
add    $0x2,%ecx
test   $0x20,%al
mov    $0x2,%edx
cmovne %edx,%ecx
mov    %eax,%r9d
shr    $0x8,%r9d
and    $0x1f,%r9d
add    $0x2,%r9d
test   $0x2000,%eax
cmovne %edx,%r9d
mov    %eax,%r8d
shr    $0x6,%r8d
and    $0x2,%r8d
add    $0x2,%r8d
shr    $0xe,%eax
and    $0x2,%eax
add    $0x2,%eax
mov    %eax,(%rsp)
lea    0xea3(%rip),%rdx
call   1030 <snprintf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [45 x i8] c"vga0 p1 = %d, p2 = %d, vga1 p1 = %d, p2 = %d\00"
define void @i830_debug_vga_pd(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%15 = load i32, i32* %9
%16 = and i32 %15, 32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %5
store i32 2, i32* %11
br label %24
19: ; preds = %5
%20 = load i32, i32* %9
%21 = and i32 %20, 31
%22 = ashr i32 %21, 0
%23 = add nsw i32 %22, 2
store i32 %23, i32* %11
br label %24
24: ; preds = %19, %18
%25 = load i32, i32* %9
%26 = and i32 %25, 128
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 4, i32 2
store i32 %29, i32* %12
%30 = load i32, i32* %9
%31 = and i32 %30, 8192
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %24
store i32 2, i32* %13
br label %39
34: ; preds = %24
%35 = load i32, i32* %9
%36 = and i32 %35, 7936
%37 = ashr i32 %36, 8
%38 = add nsw i32 %37, 2
store i32 %38, i32* %13
br label %39
39: ; preds = %34, %33
%40 = load i32, i32* %9
%41 = and i32 %40, 32768
%42 = icmp ne i32 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 4, i32 2
store i32 %44, i32* %14
%45 = load i8*, i8** %6
%46 = load i32, i32* %7
%47 = load i32, i32* %11
%48 = load i32, i32* %12
%49 = load i32, i32* %13
%50 = load i32, i32* %14
%51 = call i32 @snprintf(i8* %45, i32 %46, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %47, i32 %48, i32 %49, i32 %50)
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"vga0 p1 = %d, p2 = %d, vga1 p1 = %d, p2 = %d\00"
define void @i830_debug_vga_pd(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = and i32 %3, 32
%7 = icmp eq i32 %6, 0
%8 = and i32 %3, 31
%9 = add nuw nsw i32 %8, 2
%10 = select i1 %7, i32 %9, i32 2
%11 = and i32 %3, 8192
%12 = icmp eq i32 %11, 0
%13 = lshr i32 %3, 8
%14 = and i32 %13, 31
%15 = add nuw nsw i32 %14, 2
%16 = select i1 %12, i32 %15, i32 2
%17 = and i32 %3, 128
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i32 2, i32 4
%20 = and i32 %3, 32768
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 2, i32 4
%23 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %19, i32 %16, i32 %22)
ret void
}