#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ ehrpwm_write(int, unsigned int, unsigned short);
int ehrpwm_pwm_set_pol(uint8_t module, uint8_t polarity) {
  unsigned int act_ctrl_reg;
  unsigned int ctreqcmp;
  unsigned short val;
  int chan = module & 0x1;
  if (!chan) {
    act_ctrl_reg = 0x16;
    ctreqcmp = 4;
  } else {
    act_ctrl_reg = 0x18;
    ctreqcmp = 8;
  }
  val = ((polarity ? 0x2 : 0x1) << ctreqcmp) | (polarity ? 0x1 : 0x2);
  ehrpwm_write(module, act_ctrl_reg, val);
  return 0;
}


x86 assembly (clang, -O0):
<ehrpwm_pwm_set_pol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1144 <ehrpwm_pwm_set_pol+0x34>
movl   $0x16,-0xc(%rbp)
movl   $0x4,-0x10(%rbp)
jmp    1152 <ehrpwm_pwm_set_pol+0x42>
movl   $0x18,-0xc(%rbp)
movl   $0x8,-0x10(%rbp)
mov    -0x8(%rbp),%edx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    -0x10(%rbp),%ecx
shl    %cl,%eax
mov    -0x8(%rbp),%esi
mov    $0x2,%ecx
mov    $0x1,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
or     %ecx,%eax
mov    %ax,-0x12(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
movzwl -0x12(%rbp),%edx
call   1030 <ehrpwm_write@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ehrpwm_pwm_set_pol>:
push   %rax
mov    %edi,%ecx
and    $0x1,%ecx
lea    (%rcx,%rcx,1),%eax
add    $0x16,%eax
xor    %edx,%edx
test   %esi,%esi
sete   %dl
mov    $0x2,%esi
sub    %edx,%esi
shl    $0x2,%cl
add    $0x4,%cl
shl    %cl,%esi
add    $0x1,%edx
or     %esi,%edx
mov    %eax,%esi
call   1030 <ehrpwm_write@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @ehrpwm_pwm_set_pol(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %3
%10 = and i32 %9, 1
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 22, i32* %5
store i32 4, i32* %6
br label %15
14: ; preds = %2
store i32 24, i32* %5
store i32 8, i32* %6
br label %15
15: ; preds = %14, %13
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 2, i32 1
%20 = load i32, i32* %6
%21 = shl i32 %19, %20
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 1, i32 2
%26 = or i32 %21, %25
%27 = trunc i32 %26 to i16
store i16 %27, i16* %7
%28 = load i32, i32* %3
%29 = load i32, i32* %5
%30 = load i16, i16* %7
%31 = call i32 @ehrpwm_write(i32 %28, i32 %29, i16 zeroext %30)
ret i32 0
}

LLVM IR (-O2):
define i32 @ehrpwm_pwm_set_pol(i32 %0, i32 %1) {
%3 = and i32 %0, 1
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i16 4, i16 8
%6 = select i1 %4, i32 22, i32 24
%7 = icmp eq i32 %1, 0
%8 = select i1 %7, i16 1, i16 2
%9 = shl nuw nsw i16 %8, %5
%10 = select i1 %7, i16 2, i16 1
%11 = or i16 %9, %10
%12 = tail call i32 @ehrpwm_write(i32 %0, i32 %6, i16 zeroext %11)
ret i32 0
}