#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ get_dreg(int);
int get_opa(int);
int get_opb(int);
int /*<<< orphan*/ set_reg(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ sim_warning(char *);
int /*<<< orphan*/ update_flags(int);
void insn_logic_op(uint32_t insn) {
  uint32_t opa, opb;
  uint32_t result;
  opa = get_opa(insn);
  opb = get_opb(insn);
  switch (insn & 0x07800000) {
  case 0x00000000:
    result = opa & opb;
    break;
  case 0x01000000:
    result = opa | opb;
    break;
  case 0x02000000:
    result = opa ^ opb;
    break;
  default:
    sim_warning("Unimplemented logic instruction");
    return;
  }
  if (insn & 0x00800000) {
    update_flags(result);
  }
  set_reg(get_dreg(insn), result, 0);
}


x86 assembly (clang, -O0):
<insn_logic_op>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <get_opa@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <get_opb@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    $0x7800000,%eax
mov    %eax,-0x14(%rbp)
je     11bd <insn_logic_op+0x5d>
jmp    1197 <insn_logic_op+0x37>
mov    -0x14(%rbp),%eax
sub    $0x1000000,%eax
je     11cb <insn_logic_op+0x6b>
jmp    11aa <insn_logic_op+0x4a>
mov    -0x14(%rbp),%eax
sub    $0x2000000,%eax
je     11d9 <insn_logic_op+0x79>
jmp    11e7 <insn_logic_op+0x87>
mov    -0x8(%rbp),%eax
and    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11f8 <insn_logic_op+0x98>
mov    -0x8(%rbp),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11f8 <insn_logic_op+0x98>
mov    -0x8(%rbp),%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11f8 <insn_logic_op+0x98>
lea    0xe12(%rip),%rdi
call   1060 <sim_warning@plt>
jmp    1225 <insn_logic_op+0xc5>
mov    -0x4(%rbp),%eax
and    $0x800000,%eax
cmp    $0x0,%eax
je     1211 <insn_logic_op+0xb1>
mov    -0x10(%rbp),%edi
call   1040 <update_flags@plt>
mov    -0x4(%rbp),%edi
call   1070 <get_dreg@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%esi
xor    %edx,%edx
call   1080 <set_reg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insn_logic_op>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
call   1050 <get_opa@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1030 <get_opb@plt>
mov    %eax,%ebp
mov    %ebx,%eax
and    $0x7800000,%eax
cmp    $0x2000000,%eax
je     119d <insn_logic_op+0x3d>
cmp    $0x1000000,%eax
je     11aa <insn_logic_op+0x4a>
test   %eax,%eax
jne    11d2 <insn_logic_op+0x72>
and    %r14d,%ebp
test   $0x800000,%ebx
jne    11b5 <insn_logic_op+0x55>
jmp    11bc <insn_logic_op+0x5c>
xor    %r14d,%ebp
test   $0x800000,%ebx
jne    11b5 <insn_logic_op+0x55>
jmp    11bc <insn_logic_op+0x5c>
or     %r14d,%ebp
test   $0x800000,%ebx
je     11bc <insn_logic_op+0x5c>
mov    %ebp,%edi
call   1040 <update_flags@plt>
mov    %ebx,%edi
call   1070 <get_dreg@plt>
mov    %eax,%edi
mov    %ebp,%esi
xor    %edx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <set_reg@plt>
lea    0xe27(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <sim_warning@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Unimplemented logic instruction\00"
define void @insn_logic_op(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @get_opa(i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = call i32 @get_opb(i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %2
%11 = and i32 %10, 125829120
switch i32 %11, label %24 [
i32 0, label %12
i32 16777216, label %16
i32 33554432, label %20
]
12: ; preds = %1
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = and i32 %13, %14
store i32 %15, i32* %5
br label %26
16: ; preds = %1
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = or i32 %17, %18
store i32 %19, i32* %5
br label %26
20: ; preds = %1
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = xor i32 %21, %22
store i32 %23, i32* %5
br label %26
24: ; preds = %1
%25 = call i32 @sim_warning(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %38
26: ; preds = %20, %16, %12
%27 = load i32, i32* %2
%28 = and i32 %27, 8388608
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %5
%32 = call i32 @update_flags(i32 %31)
br label %33
33: ; preds = %30, %26
%34 = load i32, i32* %2
%35 = call i32 @get_dreg(i32 %34)
%36 = load i32, i32* %5
%37 = call i32 @set_reg(i32 %35, i32 %36, i32 0)
br label %38
38: ; preds = %33, %24
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Unimplemented logic instruction\00"
define void @insn_logic_op(i32 %0) {
%2 = tail call i32 @get_opa(i32 %0)
%3 = tail call i32 @get_opb(i32 %0)
%4 = and i32 %0, 125829120
switch i32 %4, label %11 [
i32 0, label %5
i32 16777216, label %7
i32 33554432, label %9
]
5: ; preds = %1
%6 = and i32 %3, %2
br label %13
7: ; preds = %1
%8 = or i32 %3, %2
br label %13
9: ; preds = %1
%10 = xor i32 %3, %2
br label %13
11: ; preds = %1
%12 = tail call i32 @sim_warning(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %22
13: ; preds = %9, %7, %5
%14 = phi i32 [ %10, %9 ], [ %8, %7 ], [ %6, %5 ]
%15 = and i32 %0, 8388608
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @update_flags(i32 %14)
br label %19
19: ; preds = %17, %13
%20 = tail call i32 @get_dreg(i32 %0)
%21 = tail call i32 @set_reg(i32 %20, i32 %14, i32 0)
br label %22
22: ; preds = %19, %11
ret void
}