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

/* Variables and functions */
int /*<<< orphan*/ ehrpwm_reg_config(int /*<<< orphan*/, int /*<<< orphan*/,
                                     unsigned char, int);
int ehrpwm_hr_config(uint8_t module, unsigned char loadmode,
                     unsigned char ctlmode, unsigned char edgemode) {
  if (loadmode > 1 || ctlmode > 1 || edgemode > 3)
    return -1;
  ehrpwm_reg_config(module, (uint16_t)0x1040, loadmode << 0x3, (1 << 3));
  ehrpwm_reg_config(module, (uint16_t)0x1040, ctlmode << 0x2, (1 << 2));
  ehrpwm_reg_config(module, (uint16_t)0x1040, edgemode, ((1 << 1) | (1 << 0)));
  return 0;
}


x86 assembly (clang, -O0):
<ehrpwm_hr_config>:
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    $0x1,%eax
jg     1152 <ehrpwm_hr_config+0x42>
movzbl -0xa(%rbp),%eax
cmp    $0x1,%eax
jg     1152 <ehrpwm_hr_config+0x42>
movzbl -0xb(%rbp),%eax
cmp    $0x3,%eax
jle    115e <ehrpwm_hr_config+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <ehrpwm_hr_config+0xa3>
mov    -0x8(%rbp),%edi
movzbl -0x9(%rbp),%eax
shl    $0x3,%eax
mov    $0x1040,%esi
mov    $0x8,%ecx
movzbl %al,%edx
call   1030 <ehrpwm_reg_config@plt>
mov    -0x8(%rbp),%edi
movzbl -0xa(%rbp),%eax
shl    $0x2,%eax
mov    $0x1040,%esi
mov    $0x4,%ecx
movzbl %al,%edx
call   1030 <ehrpwm_reg_config@plt>
mov    -0x8(%rbp),%edi
mov    $0x1040,%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_hr_config>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %ebx,%ecx
or     %sil,%cl
mov    $0xffffffff,%eax
cmp    $0x1,%cl
ja     1175 <ehrpwm_hr_config+0x65>
cmp    $0x3,%r14b
ja     1175 <ehrpwm_hr_config+0x65>
mov    %edi,%ebp
shl    $0x3,%sil
movzbl %sil,%edx
mov    $0x1040,%esi
mov    $0x8,%ecx
call   1030 <ehrpwm_reg_config@plt>
shl    $0x2,%bl
movzbl %bl,%edx
mov    %ebp,%edi
mov    $0x1040,%esi
mov    $0x4,%ecx
call   1030 <ehrpwm_reg_config@plt>
movzbl %r14b,%edx
mov    %ebp,%edi
mov    $0x1040,%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_hr_config(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, 1
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, 1
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, 3
%27 = trunc i32 %26 to i8
%28 = call i32 @ehrpwm_reg_config(i32 %23, i32 4160, i8 zeroext %27, i32 8)
%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 4160, i8 zeroext %33, i32 4)
%35 = load i32, i32* %6
%36 = load i8, i8* %9
%37 = call i32 @ehrpwm_reg_config(i32 %35, i32 4160, 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_hr_config(i32 %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = or i8 %2, %1
%6 = icmp ugt i8 %5, 1
%7 = icmp ugt i8 %3, 3
%8 = or i1 %6, %7
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = shl nuw nsw i8 %1, 3
%11 = tail call i32 @ehrpwm_reg_config(i32 %0, i32 4160, i8 zeroext %10, i32 8)
%12 = shl nuw nsw i8 %2, 2
%13 = tail call i32 @ehrpwm_reg_config(i32 %0, i32 4160, i8 zeroext %12, i32 4)
%14 = tail call i32 @ehrpwm_reg_config(i32 %0, i32 4160, i8 zeroext %3, i32 3)
br label %15
15: ; preds = %4, %9
%16 = phi i32 [ 0, %9 ], [ -1, %4 ]
ret i32 %16
}