#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_inc8_flags(struct cpu *cpu, unsigned char a, unsigned int t) {
  unsigned int carries = t ^ a ^ ((unsigned char)+1);
  unsigned char f = cpu_get_r8(cpu, (0));
  unsigned char z = (t & 0xFF) == 0 ? ((unsigned char)(0x80)) : 0;
  unsigned char n = 0;
  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_inc8_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
movzbl -0x9(%rbp),%ecx
xor    %ecx,%eax
xor    $0x1,%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   $0x0,-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_inc8_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
sete   %cl
xor    %ebx,%ebp
add    %bpl,%bpl
and    $0x20,%bpl
and    $0x10,%al
shl    $0x7,%cl
or     %bpl,%cl
or     %al,%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_inc8_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 = load i8, i8* %5
%15 = zext i8 %14 to i32
%16 = xor i32 %13, %15
%17 = xor i32 %16, 1
store i32 %17, i32* %7
%18 = load %struct.cpu*, %struct.cpu** %4
%19 = call zeroext i8 @cpu_get_r8(%struct.cpu* %18, i32 0)
store i8 %19, i8* %8
%20 = load i32, i32* %6
%21 = and i32 %20, 255
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 128, i32 0
%25 = trunc i32 %24 to i8
store i8 %25, i8* %9
store i8 0, i8* %10
%26 = load i32, i32* %7
%27 = and i32 %26, 16
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 32, i32 0
%31 = trunc i32 %30 to i8
store i8 %31, i8* %11
%32 = load i8, i8* %8
%33 = zext i8 %32 to i32
%34 = and i32 %33, 16
%35 = trunc i32 %34 to i8
store i8 %35, i8* %12
%36 = load %struct.cpu*, %struct.cpu** %4
%37 = load i8, i8* %9
%38 = zext i8 %37 to i32
%39 = load i8, i8* %10
%40 = zext i8 %39 to i32
%41 = or i32 %38, %40
%42 = load i8, i8* %11
%43 = zext i8 %42 to i32
%44 = or i32 %41, %43
%45 = load i8, i8* %12
%46 = zext i8 %45 to i32
%47 = or i32 %44, %46
%48 = trunc i32 %47 to i8
%49 = call i32 @cpu_set_r8(%struct.cpu* %36, i32 0, i8 zeroext %48)
ret void
}

LLVM IR (-O2):
%struct.cpu = type { i32 }
define void @cpu_inc8_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 -128, i8 0
%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
}