#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 seq_utils_clamp(scalar_t__, int /*<<< orphan*/, int);
scalar_t__ song_get_metronome_mode();
int /*<<< orphan*/ song_set_metronome_mode(int);
void seq_ctrl_adjust_metronome_mode(int change) {
  int val = seq_utils_clamp(song_get_metronome_mode() + change, 0, 84);
  if (val > 2 && val < 24) {
    if (change > 0) {
      val = 24;
    } else if (change < 0) {
      val = 2;
    }
  }
  song_set_metronome_mode(val);
}


x86 assembly (clang, -O0):
<seq_ctrl_adjust_metronome_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <song_get_metronome_mode@plt>
mov    %rax,%rdi
movslq -0x4(%rbp),%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x54,%edx
call   1050 <seq_utils_clamp@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11a0 <seq_ctrl_adjust_metronome_mode+0x70>
cmpl   $0x18,-0x8(%rbp)
jge    11a0 <seq_ctrl_adjust_metronome_mode+0x70>
cmpl   $0x0,-0x4(%rbp)
jle    1185 <seq_ctrl_adjust_metronome_mode+0x55>
movl   $0x18,-0x8(%rbp)
jmp    119b <seq_ctrl_adjust_metronome_mode+0x6b>
cmpl   $0x0,-0x4(%rbp)
jge    1196 <seq_ctrl_adjust_metronome_mode+0x66>
movl   $0x2,-0x8(%rbp)
jmp    119b <seq_ctrl_adjust_metronome_mode+0x6b>
jmp    11a0 <seq_ctrl_adjust_metronome_mode+0x70>
mov    -0x8(%rbp),%edi
call   1030 <song_set_metronome_mode@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seq_ctrl_adjust_metronome_mode>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <song_get_metronome_mode@plt>
movslq %ebx,%rdi
add    %rax,%rdi
xor    %esi,%esi
mov    $0x54,%edx
call   1050 <seq_utils_clamp@plt>
lea    -0x3(%rax),%ecx
mov    %eax,%edi
cmp    $0x14,%ecx
ja     115f <seq_ctrl_adjust_metronome_mode+0x2f>
mov    $0x18,%edi
test   %ebx,%ebx
jle    1165 <seq_ctrl_adjust_metronome_mode+0x35>
pop    %rbx
jmp    1030 <song_set_metronome_mode@plt>
mov    $0x2,%edi
cmove  %eax,%edi
pop    %rbx
jmp    1030 <song_set_metronome_mode@plt>

LLVM IR (-O0):
define void @seq_ctrl_adjust_metronome_mode(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i64 (...) @song_get_metronome_mode()
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = add nsw i64 %4, %6
%8 = call i32 @seq_utils_clamp(i64 %7, i32 0, i32 84)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 2
br i1 %10, label %11, label %24
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 24
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 24, i32* %3
br label %23
18: ; preds = %14
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 2, i32* %3
br label %22
22: ; preds = %21, %18
br label %23
23: ; preds = %22, %17
br label %24
24: ; preds = %23, %11, %1
%25 = load i32, i32* %3
%26 = call i32 @song_set_metronome_mode(i32 %25)
ret void
}

LLVM IR (-O2):
define void @seq_ctrl_adjust_metronome_mode(i32 %0) {
%2 = tail call i64 (...) @song_get_metronome_mode()
%3 = sext i32 %0 to i64
%4 = add nsw i64 %2, %3
%5 = tail call i32 @seq_utils_clamp(i64 %4, i32 0, i32 84)
%6 = add i32 %5, -3
%7 = icmp ult i32 %6, 21
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = icmp sgt i32 %0, 0
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = icmp eq i32 %0, 0
%12 = select i1 %11, i32 %5, i32 2
br label %13
13: ; preds = %10, %8, %1
%14 = phi i32 [ %5, %1 ], [ 24, %8 ], [ %12, %10 ]
%15 = tail call i32 @song_set_metronome_mode(i32 %14)
ret void
}