#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 */
struct cpu {
  int dummy;
};

/* Variables and functions */
unsigned char cpu_get_r8(struct cpu *, int /*<<< orphan*/);
int /*<<< orphan*/ cpu_set_r8(struct cpu *, int /*<<< orphan*/, unsigned char);
void cpu_dec8_flags(struct cpu *cpu, unsigned char a, signed int t) {
  unsigned int carries = (t ^ 0x1FF) ^ a ^ ((signed char)-1);
  unsigned char f = cpu_get_r8(cpu, (0));
  unsigned char z = (t & 0xFF) == 0 ? ((unsigned char)(0x80)) : 0;
  unsigned char n = ((unsigned char)(0x40));
  unsigned char h = carries & 0x10 ? ((unsigned char)(0x20)) : 0;
  unsigned char c = f & ((unsigned char)(0x10));
  cpu_set_r8(cpu, (0), z | n | h | c);
}


x86 assembly (clang, -O0):
<cpu_dec8_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
xor    $0x1ff,%eax
movzbl -0x9(%rbp),%ecx
xor    %ecx,%eax
xor    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <cpu_get_r8@plt>
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%edx
and    $0xff,%edx
xor    %eax,%eax
mov    $0x80,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %al,-0x16(%rbp)
movb   $0x40,-0x17(%rbp)
mov    -0x14(%rbp),%edx
and    $0x10,%edx
xor    %eax,%eax
mov    $0x20,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x18(%rbp)
movzbl -0x15(%rbp),%eax
and    $0x10,%eax
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
movzbl -0x16(%rbp),%eax
movzbl -0x17(%rbp),%ecx
or     %ecx,%eax
movzbl -0x18(%rbp),%ecx
or     %ecx,%eax
movzbl -0x19(%rbp),%ecx
or     %ecx,%eax
xor    %esi,%esi
movzbl %al,%edx
call   1040 <cpu_set_r8@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_dec8_flags>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %esi,%esi
call   1030 <cpu_get_r8@plt>
test   %bl,%bl
setne  %cl
xor    %ebx,%ebp
add    %bpl,%bpl
and    $0x20,%bpl
and    $0x10,%al
shl    $0x7,%cl
or     %bpl,%cl
or     %al,%cl
add    $0xc0,%cl
movzbl %cl,%edx
mov    %r14,%rdi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <cpu_set_r8@plt>

LLVM IR (-O0):
%struct.cpu = type { i32 }
define void @cpu_dec8_flags(%struct.cpu* %0, i8 zeroext %1, i32 %2) {
%4 = alloca %struct.cpu*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
store %struct.cpu* %0, %struct.cpu** %4
store i8 %1, i8* %5
store i32 %2, i32* %6
%13 = load i32, i32* %6
%14 = xor i32 %13, 511
%15 = load i8, i8* %5
%16 = zext i8 %15 to i32
%17 = xor i32 %14, %16
%18 = xor i32 %17, -1
store i32 %18, i32* %7
%19 = load %struct.cpu*, %struct.cpu** %4
%20 = call zeroext i8 @cpu_get_r8(%struct.cpu* %19, i32 0)
store i8 %20, i8* %8
%21 = load i32, i32* %6
%22 = and i32 %21, 255
%23 = icmp eq i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 128, i32 0
%26 = trunc i32 %25 to i8
store i8 %26, i8* %9
store i8 64, i8* %10
%27 = load i32, i32* %7
%28 = and i32 %27, 16
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 32, i32 0
%32 = trunc i32 %31 to i8
store i8 %32, i8* %11
%33 = load i8, i8* %8
%34 = zext i8 %33 to i32
%35 = and i32 %34, 16
%36 = trunc i32 %35 to i8
store i8 %36, i8* %12
%37 = load %struct.cpu*, %struct.cpu** %4
%38 = load i8, i8* %9
%39 = zext i8 %38 to i32
%40 = load i8, i8* %10
%41 = zext i8 %40 to i32
%42 = or i32 %39, %41
%43 = load i8, i8* %11
%44 = zext i8 %43 to i32
%45 = or i32 %42, %44
%46 = load i8, i8* %12
%47 = zext i8 %46 to i32
%48 = or i32 %45, %47
%49 = trunc i32 %48 to i8
%50 = call i32 @cpu_set_r8(%struct.cpu* %37, i32 0, i8 zeroext %49)
ret void
}

LLVM IR (-O2):
%struct.cpu = type { i32 }
define void @cpu_dec8_flags(%struct.cpu* %0, i8 zeroext %1, i32 %2) {
%4 = tail call zeroext i8 @cpu_get_r8(%struct.cpu* %0, i32 0)
%5 = and i32 %2, 255
%6 = icmp eq i32 %5, 0
%7 = trunc i32 %2 to i8
%8 = xor i8 %7, %1
%9 = shl i8 %8, 1
%10 = and i8 %9, 32
%11 = and i8 %4, 16
%12 = select i1 %6, i8 -64, i8 64
%13 = or i8 %10, %12
%14 = or i8 %13, %11
%15 = tail call i32 @cpu_set_r8(%struct.cpu* %0, i32 0, i8 zeroext %14)
ret void
}