#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_db_set_mode(uint8_t module, unsigned char inmode,
                       unsigned char polsel, unsigned char outmode) {
  if (inmode > 0x3 || polsel > 0x3 || outmode > 0x3)
    return -1;
  ehrpwm_reg_config(module, 0x1E, inmode << 0x4, ((1 << 5) | (1 << 4)));
  ehrpwm_reg_config(module, 0x1E, polsel << 0x2, ((1 << 3) | (1 << 2)));
  ehrpwm_reg_config(module, 0x1E, outmode, ((1 << 1) | (1 << 0)));
  return 0;
}


x86 assembly (clang, -O0):
<ehrpwm_db_set_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %edi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %cl,-0xa(%rbp)
mov    %al,-0xb(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x3,%eax
jg     1152 <ehrpwm_db_set_mode+0x42>
movzbl -0xa(%rbp),%eax
cmp    $0x3,%eax
jg     1152 <ehrpwm_db_set_mode+0x42>
movzbl -0xb(%rbp),%eax
cmp    $0x3,%eax
jle    115e <ehrpwm_db_set_mode+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <ehrpwm_db_set_mode+0xa3>
mov    -0x8(%rbp),%edi
movzbl -0x9(%rbp),%eax
shl    $0x4,%eax
mov    $0x1e,%esi
mov    $0x30,%ecx
movzbl %al,%edx
call   1030 <ehrpwm_reg_config@plt>
mov    -0x8(%rbp),%edi
movzbl -0xa(%rbp),%eax
shl    $0x2,%eax
mov    $0x1e,%esi
mov    $0xc,%ecx
movzbl %al,%edx
call   1030 <ehrpwm_reg_config@plt>
mov    -0x8(%rbp),%edi
mov    $0x1e,%esi
mov    $0x3,%ecx
movzbl -0xb(%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_db_set_mode>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %ebx,%ecx
or     %sil,%cl
or     %r14b,%cl
mov    $0xffffffff,%eax
cmp    $0x3,%cl
ja     1172 <ehrpwm_db_set_mode+0x62>
mov    %edi,%ebp
shl    $0x4,%sil
movzbl %sil,%edx
mov    $0x1e,%esi
mov    $0x30,%ecx
call   1030 <ehrpwm_reg_config@plt>
shl    $0x2,%bl
movzbl %bl,%edx
mov    %ebp,%edi
mov    $0x1e,%esi
mov    $0xc,%ecx
call   1030 <ehrpwm_reg_config@plt>
movzbl %r14b,%edx
mov    %ebp,%edi
mov    $0x1e,%esi
mov    $0x3,%ecx
call   1030 <ehrpwm_reg_config@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ehrpwm_db_set_mode(i32 %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
store i32 %0, i32* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8 %3, i8* %9
%10 = load i8, i8* %7
%11 = zext i8 %10 to i32
%12 = icmp sgt i32 %11, 3
br i1 %12, label %21, label %13
13: ; preds = %4
%14 = load i8, i8* %8
%15 = zext i8 %14 to i32
%16 = icmp sgt i32 %15, 3
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i8, i8* %9
%19 = zext i8 %18 to i32
%20 = icmp sgt i32 %19, 3
br i1 %20, label %21, label %22
21: ; preds = %17, %13, %4
store i32 -1, i32* %5
br label %38
22: ; preds = %17
%23 = load i32, i32* %6
%24 = load i8, i8* %7
%25 = zext i8 %24 to i32
%26 = shl i32 %25, 4
%27 = trunc i32 %26 to i8
%28 = call i32 @ehrpwm_reg_config(i32 %23, i32 30, i8 zeroext %27, i32 48)
%29 = load i32, i32* %6
%30 = load i8, i8* %8
%31 = zext i8 %30 to i32
%32 = shl i32 %31, 2
%33 = trunc i32 %32 to i8
%34 = call i32 @ehrpwm_reg_config(i32 %29, i32 30, i8 zeroext %33, i32 12)
%35 = load i32, i32* %6
%36 = load i8, i8* %9
%37 = call i32 @ehrpwm_reg_config(i32 %35, i32 30, i8 zeroext %36, i32 3)
store i32 0, i32* %5
br label %38
38: ; preds = %22, %21
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
define i32 @ehrpwm_db_set_mode(i32 %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = or i8 %2, %1
%6 = or i8 %5, %3
%7 = icmp ult i8 %6, 4
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = shl i8 %1, 4
%10 = tail call i32 @ehrpwm_reg_config(i32 %0, i32 30, i8 zeroext %9, i32 48)
%11 = shl i8 %2, 2
%12 = tail call i32 @ehrpwm_reg_config(i32 %0, i32 30, i8 zeroext %11, i32 12)
%13 = tail call i32 @ehrpwm_reg_config(i32 %0, i32 30, i8 zeroext %3, i32 3)
br label %14
14: ; preds = %4, %8
%15 = phi i32 [ 0, %8 ], [ -1, %4 ]
ret i32 %15
}