#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_add16_flags(struct cpu *cpu, unsigned short a, unsigned short b,
                     unsigned int t) {
  unsigned int carries = t ^ a ^ b;
  unsigned char z = t & 0xFFFF ? 0 : ((unsigned char)(0x80));
  unsigned char n = 0;
  unsigned char h = carries & 0x1000 ? ((unsigned char)(0x20)) : 0;
  unsigned char c = carries & 0x10000 ? ((unsigned char)(0x10)) : 0;
  cpu_set_r8(cpu, (0), z | n | h | c);
}


x86 assembly (clang, -O0):
<cpu_add16_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %si,%dx
mov    %rdi,-0x8(%rbp)
mov    %dx,-0xa(%rbp)
mov    %ax,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
movzwl -0xa(%rbp),%ecx
xor    %ecx,%eax
movzwl -0xc(%rbp),%ecx
xor    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edx
and    $0xffff,%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    $0x1000,%edx
xor    %eax,%eax
mov    $0x20,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x17(%rbp)
mov    -0x14(%rbp),%edx
and    $0x10000,%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_add16_flags>:
xor    %ecx,%esi
xor    %esi,%edx
xor    %eax,%eax
test   %cx,%cx
sete   %al
shr    $0x7,%edx
and    $0x20,%edx
shr    $0xc,%ecx
and    $0x10,%ecx
shl    $0x7,%eax
or     %ecx,%eax
or     %eax,%edx
xor    %esi,%esi
jmp    1030 <cpu_set_r8@plt>

LLVM IR (-O0):
%struct.cpu = type { i32 }
define void @cpu_add16_flags(%struct.cpu* %0, i16 zeroext %1, i16 zeroext %2, i32 %3) {
%5 = alloca %struct.cpu*
%6 = alloca i16
%7 = alloca i16
%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 i16 %1, i16* %6
store i16 %2, i16* %7
store i32 %3, i32* %8
%14 = load i32, i32* %8
%15 = load i16, i16* %6
%16 = zext i16 %15 to i32
%17 = xor i32 %14, %16
%18 = load i16, i16* %7
%19 = zext i16 %18 to i32
%20 = xor i32 %17, %19
store i32 %20, i32* %9
%21 = load i32, i32* %8
%22 = and i32 %21, 65535
%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, 4096
%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, 65536
%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_add16_flags(%struct.cpu* %0, i16 zeroext %1, i16 zeroext %2, i32 %3) {
%5 = zext i16 %1 to i32
%6 = xor i32 %5, %3
%7 = zext i16 %2 to i32
%8 = xor i32 %6, %7
%9 = and i32 %3, 65535
%10 = icmp eq i32 %9, 0
%11 = lshr i32 %8, 7
%12 = and i32 %11, 32
%13 = lshr i32 %3, 12
%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
}