#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*/ printf(char *, int, int);
int read_pci_conf(char *, int);
int /*<<< orphan*/ write_pci_conf(char *, int, int);
void set_ht_err_type(char *path, int type) {
  uint32_t oldV = read_pci_conf(path, 0x150);
  printf("0x%08x, type is 0x%x\n", oldV, ((oldV & (3 << 5)) >> 5));
  uint32_t newV = (oldV & (~(3 << 5))) | (type << 5);
  printf("0x%08x, type is 0x%x\n", newV, ((newV & (3 << 5)) >> 5));
  write_pci_conf(path, 0x150, newV);
}


x86 assembly (clang, -O0):
<set_ht_err_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x150,%esi
call   1050 <read_pci_conf@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
and    $0x60,%edx
sar    $0x5,%edx
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
and    $0xffffff9f,%eax
mov    -0xc(%rbp),%ecx
shl    $0x5,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
and    $0x60,%edx
sar    $0x5,%edx
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x150,%esi
call   1040 <write_pci_conf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ht_err_type>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%r14
mov    $0x150,%esi
call   1050 <read_pci_conf@plt>
mov    %eax,%ebx
mov    %eax,%edx
shr    $0x5,%edx
and    $0x3,%edx
lea    0xea7(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
and    $0xffffff9f,%ebx
mov    %r12d,%ebp
shl    $0x5,%ebp
or     %ebx,%ebp
and    $0x3,%r12d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x150,%esi
mov    %ebp,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <write_pci_conf@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"0x%08x, type is 0x%x\0A\00"
define void @set_ht_err_type(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @read_pci_conf(i8* %7, i32 336)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i32, i32* %5
%11 = and i32 %10, 96
%12 = ashr i32 %11, 5
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %12)
%14 = load i32, i32* %5
%15 = and i32 %14, -97
%16 = load i32, i32* %4
%17 = shl i32 %16, 5
%18 = or i32 %15, %17
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = load i32, i32* %6
%21 = and i32 %20, 96
%22 = ashr i32 %21, 5
%23 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %22)
%24 = load i8*, i8** %3
%25 = load i32, i32* %6
%26 = call i32 @write_pci_conf(i8* %24, i32 336, i32 %25)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"0x%08x, type is 0x%x\0A\00"
define void @set_ht_err_type(i8* %0, i32 %1) {
%3 = tail call i32 @read_pci_conf(i8* %0, i32 336)
%4 = lshr i32 %3, 5
%5 = and i32 %4, 3
%6 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %5)
%7 = and i32 %3, -97
%8 = shl i32 %1, 5
%9 = or i32 %7, %8
%10 = and i32 %1, 3
%11 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = tail call i32 @write_pci_conf(i8* %0, i32 336, i32 %9)
ret void
}