#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 */
int /*<<< orphan*/ cpu_set_r8(struct cpu *, int /*<<< orphan*/, unsigned char);
void cpu_add8_flags(struct cpu *cpu, unsigned char a, unsigned char b,
                    unsigned int t) {
  unsigned int carries = t ^ a ^ b;
  unsigned char z = t & 0xFF ? 0 : ((unsigned char)(0x80));
  unsigned char n = 0;
  unsigned char h = carries & 0x10 ? ((unsigned char)(0x20)) : 0;
  unsigned char c = carries & 0x100 ? ((unsigned char)(0x10)) : 0;
  cpu_set_r8(cpu, (0), z | n | h | c);
}


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

x86 assembly (clang, -O2):
<cpu_add8_flags>:
xor    %ecx,%esi
xor    %edx,%esi
xor    %eax,%eax
test   %cl,%cl
sete   %al
and    $0x10,%esi
shr    $0x4,%ecx
and    $0x10,%ecx
shl    $0x7,%eax
or     %ecx,%eax
lea    (%rax,%rsi,2),%edx
xor    %esi,%esi
jmp    1030 <cpu_set_r8@plt>

LLVM IR (-O0):
%struct.cpu = type { i32 }
define void @cpu_add8_flags(%struct.cpu* %0, i8 zeroext %1, i8 zeroext %2, i32 %3) {
%5 = alloca %struct.cpu*
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
store %struct.cpu* %0, %struct.cpu** %5
store i8 %1, i8* %6
store i8 %2, i8* %7
store i32 %3, i32* %8
%14 = load i32, i32* %8
%15 = load i8, i8* %6
%16 = zext i8 %15 to i32
%17 = xor i32 %14, %16
%18 = load i8, i8* %7
%19 = zext i8 %18 to i32
%20 = xor i32 %17, %19
store i32 %20, i32* %9
%21 = load i32, i32* %8
%22 = and i32 %21, 255
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 0, i32 128
%26 = trunc i32 %25 to i8
store i8 %26, i8* %10
store i8 0, i8* %11
%27 = load i32, i32* %9
%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* %12
%33 = load i32, i32* %9
%34 = and i32 %33, 256
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 16, i32 0
%38 = trunc i32 %37 to i8
store i8 %38, i8* %13
%39 = load %struct.cpu*, %struct.cpu** %5
%40 = load i8, i8* %10
%41 = zext i8 %40 to i32
%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 = load i8, i8* %13
%49 = zext i8 %48 to i32
%50 = or i32 %47, %49
%51 = trunc i32 %50 to i8
%52 = call i32 @cpu_set_r8(%struct.cpu* %39, i32 0, i8 zeroext %51)
ret void
}

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