#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 ffs(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int);
void i830_debug_fp(char *result, int len, int reg, uint32_t val,
                   uint32_t devid) {
  if ((((devid) == 0xA001) || ((devid) == 0xA011))) {
    snprintf(result, len, "n = %d, m1 = %d, m2 = %d",
             ffs((val & 0x00ff0000) >> 16) - 1, ((val & 0x00003f00) >> 8),
             ((val & 0x000000ff) >> 0));
  }
  snprintf(result, len, "n = %d, m1 = %d, m2 = %d", ((val & 0x003f0000) >> 16),
           ((val & 0x00003f00) >> 8), ((val & 0x0000003f) >> 0));
}


x86 assembly (clang, -O0):
<i830_debug_fp>:
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)
cmpl   $0xa001,-0x18(%rbp)
je     1153 <i830_debug_fp+0x33>
cmpl   $0xa011,-0x18(%rbp)
jne    11a8 <i830_debug_fp+0x88>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
and    $0xff0000,%edi
sar    $0x10,%edi
call   1040 <ffs@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    %eax,%ecx
sub    $0x1,%ecx
mov    -0x14(%rbp),%r8d
and    $0x3f00,%r8d
sar    $0x8,%r8d
mov    -0x14(%rbp),%r9d
and    $0xff,%r9d
sar    $0x0,%r9d
lea    0xe5d(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%ecx
and    $0x3f0000,%ecx
sar    $0x10,%ecx
mov    -0x14(%rbp),%r8d
and    $0x3f00,%r8d
sar    $0x8,%r8d
mov    -0x14(%rbp),%r9d
and    $0x3f,%r9d
sar    $0x0,%r9d
lea    0xe23(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i830_debug_fp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %esi,%r14d
mov    %rdi,%r15
and    $0xffffffef,%r8d
mov    %ecx,%ebx
shr    $0x10,%ebx
cmp    $0xa001,%r8d
jne    1165 <i830_debug_fp+0x55>
movzbl %bl,%eax
bsf    %eax,%eax
mov    $0xffffffff,%ecx
cmovne %eax,%ecx
mov    %r12d,%ebp
shr    $0x8,%ebp
and    $0x3f,%ebp
movzbl %r12b,%r9d
lea    0xeab(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%r8d
call   1030 <snprintf@plt>
jmp    116e <i830_debug_fp+0x5e>
mov    %r12d,%ebp
shr    $0x8,%ebp
and    $0x3f,%ebp
and    $0x3f,%ebx
and    $0x3f,%r12d
lea    0xe84(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r12d,%r9d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"n = %d, m1 = %d, m2 = %d\00"
define void @i830_debug_fp(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
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
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 40961
br i1 %12, label %16, label %13
13: ; preds = %5
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, 40977
br i1 %15, label %16, label %31
16: ; preds = %13, %5
%17 = load i8*, i8** %6
%18 = load i32, i32* %7
%19 = load i32, i32* %9
%20 = and i32 %19, 16711680
%21 = ashr i32 %20, 16
%22 = call i32 @ffs(i32 %21)
%23 = sub nsw i32 %22, 1
%24 = load i32, i32* %9
%25 = and i32 %24, 16128
%26 = ashr i32 %25, 8
%27 = load i32, i32* %9
%28 = and i32 %27, 255
%29 = ashr i32 %28, 0
%30 = call i32 @snprintf(i8* %17, i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %26, i32 %29)
br label %31
31: ; preds = %16, %13
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = load i32, i32* %9
%35 = and i32 %34, 4128768
%36 = ashr i32 %35, 16
%37 = load i32, i32* %9
%38 = and i32 %37, 16128
%39 = ashr i32 %38, 8
%40 = load i32, i32* %9
%41 = and i32 %40, 63
%42 = ashr i32 %41, 0
%43 = call i32 @snprintf(i8* %32, i32 %33, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %39, i32 %42)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"n = %d, m1 = %d, m2 = %d\00"
define void @i830_debug_fp(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = and i32 %4, -17
%7 = icmp eq i32 %6, 40961
%8 = lshr i32 %3, 16
br i1 %7, label %12, label %9
9: ; preds = %5
%10 = lshr i32 %3, 8
%11 = and i32 %10, 63
br label %21
12: ; preds = %5
%13 = and i32 %8, 255
%14 = tail call i32 @llvm.cttz.i32(i32 %13, i1 true)
%15 = icmp eq i32 %13, 0
%16 = select i1 %15, i32 -1, i32 %14
%17 = lshr i32 %3, 8
%18 = and i32 %17, 63
%19 = and i32 %3, 255
%20 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18, i32 %19)
br label %21
21: ; preds = %9, %12
%22 = phi i32 [ %11, %9 ], [ %18, %12 ]
%23 = and i32 %8, 63
%24 = and i32 %3, 63
%25 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %22, i32 %24)
ret void
}