#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_prescalar_val(uint8_t module, unsigned char clkdiv,
                                unsigned char hspclkdiv) {
  if (clkdiv > 0x7 || hspclkdiv > 0x7)
    return -1;
  ehrpwm_reg_config(module, 0x0, clkdiv << 0xA,
                    ((1 << 12) | (1 << 11) | (1 << 10)));
  ehrpwm_reg_config(module, 0x0, hspclkdiv << 0x7,
                    ((1 << 9) | (1 << 8) | (1 << 7)));
  return 0;
}


x86 assembly (clang, -O0):
<ehrpwm_tb_set_prescalar_val>:
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    $0x7,%eax
jg     1140 <ehrpwm_tb_set_prescalar_val+0x30>
movzbl -0xa(%rbp),%eax
cmp    $0x7,%eax
jle    114c <ehrpwm_tb_set_prescalar_val+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1185 <ehrpwm_tb_set_prescalar_val+0x75>
mov    -0x8(%rbp),%edi
movzbl -0x9(%rbp),%eax
shl    $0xa,%eax
xor    %esi,%esi
mov    $0x1c00,%ecx
movzbl %al,%edx
call   1030 <ehrpwm_reg_config@plt>
mov    -0x8(%rbp),%edi
movzbl -0xa(%rbp),%eax
shl    $0x7,%eax
xor    %esi,%esi
mov    $0x380,%ecx
movzbl %al,%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_prescalar_val>:
push   %rbp
push   %r14
push   %rbx
or     %edx,%esi
mov    $0xffffffff,%ebx
cmp    $0x7,%sil
ja     114d <ehrpwm_tb_set_prescalar_val+0x3d>
mov    %edx,%ebp
mov    %edi,%r14d
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
mov    $0x1c00,%ecx
call   1030 <ehrpwm_reg_config@plt>
shl    $0x7,%bpl
movzbl %bpl,%edx
mov    %r14d,%edi
xor    %esi,%esi
mov    $0x380,%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_prescalar_val(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, 7
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, 7
br i1 %14, label %15, label %16
15: ; preds = %11, %3
store i32 -1, i32* %4
br label %29
16: ; preds = %11
%17 = load i32, i32* %5
%18 = load i8, i8* %6
%19 = zext i8 %18 to i32
%20 = shl i32 %19, 10
%21 = trunc i32 %20 to i8
%22 = call i32 @ehrpwm_reg_config(i32 %17, i32 0, i8 zeroext %21, i32 7168)
%23 = load i32, i32* %5
%24 = load i8, i8* %7
%25 = zext i8 %24 to i32
%26 = shl i32 %25, 7
%27 = trunc i32 %26 to i8
%28 = call i32 @ehrpwm_reg_config(i32 %23, i32 0, i8 zeroext %27, i32 896)
store i32 0, i32* %4
br label %29
29: ; preds = %16, %15
%30 = load i32, i32* %4
ret i32 %30
}

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