#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 */

/* Variables and functions */
int /*<<< orphan*/ log_error(char *, int);
int /*<<< orphan*/ seq_utils_clamp(scalar_t__, int, int);
scalar_t__ song_get_cvcal(int);
int /*<<< orphan*/ song_set_cvcal(int, int /*<<< orphan*/);
void seq_ctrl_adjust_cvcal(int channel, int change) {
  if (channel < 0 || channel >= 4) {
    log_error("scacc - channel invalid: %d", channel);
    return;
  }
  song_set_cvcal(channel,
                 seq_utils_clamp(song_get_cvcal(channel) + change, -100, 100));
}


x86 assembly (clang, -O0):
<seq_ctrl_adjust_cvcal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1162 <seq_ctrl_adjust_cvcal+0x22>
cmpl   $0x4,-0x4(%rbp)
jl     1176 <seq_ctrl_adjust_cvcal+0x36>
mov    -0x4(%rbp),%esi
lea    0xe94(%rip),%rdi
call   1040 <log_error@plt>
jmp    11a7 <seq_ctrl_adjust_cvcal+0x67>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <song_get_cvcal@plt>
mov    %rax,%rdi
movslq -0x8(%rbp),%rax
add    %rax,%rdi
mov    $0xffffff9c,%esi
mov    $0x64,%edx
call   1060 <seq_utils_clamp@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%esi
call   1030 <song_set_cvcal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seq_ctrl_adjust_cvcal>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cmp    $0x4,%edi
jb     115e <seq_ctrl_adjust_cvcal+0x1e>
lea    0xeaf(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <log_error@plt>
mov    %esi,%ebp
mov    %ebx,%edi
call   1050 <song_get_cvcal@plt>
movslq %ebp,%rdi
add    %rax,%rdi
mov    $0xffffff9c,%esi
mov    $0x64,%edx
call   1060 <seq_utils_clamp@plt>
mov    %ebx,%edi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <song_set_cvcal@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"scacc - channel invalid: %d\00"
define void @seq_ctrl_adjust_cvcal(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp sge i32 %8, 4
br i1 %9, label %10, label %13
10: ; preds = %7, %2
%11 = load i32, i32* %3
%12 = call i32 @log_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %22
13: ; preds = %7
%14 = load i32, i32* %3
%15 = load i32, i32* %3
%16 = call i64 @song_get_cvcal(i32 %15)
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = add nsw i64 %16, %18
%20 = call i32 @seq_utils_clamp(i64 %19, i32 -100, i32 100)
%21 = call i32 @song_set_cvcal(i32 %14, i32 %20)
br label %22
22: ; preds = %13, %10
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"scacc - channel invalid: %d\00"
define void @seq_ctrl_adjust_cvcal(i32 %0, i32 %1) {
%3 = icmp ugt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @log_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %12
6: ; preds = %2
%7 = tail call i64 @song_get_cvcal(i32 %0)
%8 = sext i32 %1 to i64
%9 = add nsw i64 %7, %8
%10 = tail call i32 @seq_utils_clamp(i64 %9, i32 -100, i32 100)
%11 = tail call i32 @song_set_cvcal(i32 %0, i32 %10)
br label %12
12: ; preds = %6, %4
ret void
}