#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_cp_flags(struct cpu *cpu, unsigned char a, unsigned char b) {
  unsigned char z = a == b ? ((unsigned char)(0x80)) : 0;
  unsigned char n = ((unsigned char)(0x40));
  unsigned char h = (a & 0x0F) < (b & 0x0F) ? ((unsigned char)(0x20)) : 0;
  unsigned char c = (a & 0xFF) < (b & 0xFF) ? ((unsigned char)(0x10)) : 0;
  cpu_set_r8(cpu, (0), z | n | h | c);
}


x86 assembly (clang, -O0):
<cpu_cp_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
movzbl -0x9(%rbp),%edx
movzbl -0xa(%rbp),%esi
xor    %eax,%eax
mov    $0x80,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %al,-0xb(%rbp)
movb   $0x40,-0xc(%rbp)
movzbl -0x9(%rbp),%edx
and    $0xf,%edx
movzbl -0xa(%rbp),%esi
and    $0xf,%esi
xor    %eax,%eax
mov    $0x20,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
mov    %al,-0xd(%rbp)
movzbl -0x9(%rbp),%edx
and    $0xff,%edx
movzbl -0xa(%rbp),%esi
and    $0xff,%esi
xor    %eax,%eax
mov    $0x10,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%rdi
movzbl -0xb(%rbp),%eax
movzbl -0xc(%rbp),%ecx
or     %ecx,%eax
movzbl -0xd(%rbp),%ecx
or     %ecx,%eax
movzbl -0xe(%rbp),%ecx
or     %ecx,%eax
xor    %esi,%esi
movzbl %al,%edx
call   1030 <cpu_set_r8@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_cp_flags>:
mov    %esi,%eax
and    $0xf,%al
mov    %edx,%ecx
and    $0xf,%cl
cmp    %cl,%al
setb   %al
cmp    %dl,%sil
setne  %cl
setb   %dl
shl    $0x4,%dl
shl    $0x7,%cl
or     %dl,%cl
shl    $0x5,%al
or     %cl,%al
add    $0xc0,%al
movzbl %al,%edx
xor    %esi,%esi
jmp    1030 <cpu_set_r8@plt>

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