#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ ehrpwm_reg_config(int /*<<< orphan*/, int, unsigned char,
                                     int);
int ehrpwm_tb_set_counter_mode(uint8_t module, unsigned char ctrmode,
                               unsigned char phsdir) {
  if (ctrmode > 0x3 || phsdir > 1)
    return -1;
  ehrpwm_reg_config(module, 0x0, phsdir << 0xD, (1 << 13));
  ehrpwm_reg_config(module, 0x0, ctrmode, ((1 << 1) | (1 << 0)));
  return 0;
}


x86 assembly (clang, -O0):
<ehrpwm_tb_set_counter_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %edi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x3,%eax
jg     1140 <ehrpwm_tb_set_counter_mode+0x30>
movzbl -0xa(%rbp),%eax
cmp    $0x1,%eax
jle    114c <ehrpwm_tb_set_counter_mode+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <ehrpwm_tb_set_counter_mode+0x6f>
mov    -0x8(%rbp),%edi
movzbl -0xa(%rbp),%eax
shl    $0xd,%eax
xor    %esi,%esi
mov    $0x2000,%ecx
movzbl %al,%edx
call   1030 <ehrpwm_reg_config@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0x3,%ecx
movzbl -0x9(%rbp),%edx
call   1030 <ehrpwm_reg_config@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ehrpwm_tb_set_counter_mode>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    $0xffffffff,%ebx
cmp    $0x3,%bpl
ja     114c <ehrpwm_tb_set_counter_mode+0x3c>
cmp    $0x1,%dl
ja     114c <ehrpwm_tb_set_counter_mode+0x3c>
mov    %edi,%r14d
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
mov    $0x2000,%ecx
call   1030 <ehrpwm_reg_config@plt>
movzbl %bpl,%edx
mov    %r14d,%edi
xor    %esi,%esi
mov    $0x3,%ecx
call   1030 <ehrpwm_reg_config@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ehrpwm_tb_set_counter_mode(i32 %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8 %2, i8* %7
%8 = load i8, i8* %6
%9 = zext i8 %8 to i32
%10 = icmp sgt i32 %9, 3
br i1 %10, label %15, label %11
11: ; preds = %3
%12 = load i8, i8* %7
%13 = zext i8 %12 to i32
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %11, %3
store i32 -1, i32* %4
br label %26
16: ; preds = %11
%17 = load i32, i32* %5
%18 = load i8, i8* %7
%19 = zext i8 %18 to i32
%20 = shl i32 %19, 13
%21 = trunc i32 %20 to i8
%22 = call i32 @ehrpwm_reg_config(i32 %17, i32 0, i8 zeroext %21, i32 8192)
%23 = load i32, i32* %5
%24 = load i8, i8* %6
%25 = call i32 @ehrpwm_reg_config(i32 %23, i32 0, i8 zeroext %24, i32 3)
store i32 0, i32* %4
br label %26
26: ; preds = %16, %15
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
define i32 @ehrpwm_tb_set_counter_mode(i32 %0, i8 zeroext %1, i8 zeroext %2) {
%4 = icmp ugt i8 %1, 3
%5 = icmp ugt i8 %2, 1
%6 = or i1 %4, %5
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i32 @ehrpwm_reg_config(i32 %0, i32 0, i8 zeroext 0, i32 8192)
%9 = tail call i32 @ehrpwm_reg_config(i32 %0, i32 0, i8 zeroext %1, i32 3)
br label %10
10: ; preds = %3, %7
%11 = phi i32 [ 0, %7 ], [ -1, %3 ]
ret i32 %11
}