#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_engine_get_current_scene();
int seq_utils_clamp(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ song_set_arp_speed(int /*<<< orphan*/, int, int);
void seq_ctrl_set_arp_speed(int track, int speed) {
  int i, val;
  val = seq_utils_clamp(speed, 0, (17 - 1));
  if (track == -1) {
    for (i = 0; i < 6; i++) {
      song_set_arp_speed(seq_engine_get_current_scene(), i, val);
    }
  } else {
    if (track < 0 || track >= 6) {
      log_error("scsas - track invalid: %d", track);
      return;
    }
    song_set_arp_speed(seq_engine_get_current_scene(), track, val);
  }
}


x86 assembly (clang, -O0):
<seq_ctrl_set_arp_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <seq_utils_clamp@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11a2 <seq_ctrl_set_arp_speed+0x62>
movl   $0x0,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jge    119d <seq_ctrl_set_arp_speed+0x5d>
mov    $0x0,%al
call   1050 <seq_engine_get_current_scene@plt>
mov    %eax,%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <song_set_arp_speed@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1171 <seq_ctrl_set_arp_speed+0x31>
jmp    11de <seq_ctrl_set_arp_speed+0x9e>
cmpl   $0x0,-0x4(%rbp)
jl     11b6 <seq_ctrl_set_arp_speed+0x76>
cmpl   $0x6,-0x4(%rbp)
jl     11ca <seq_ctrl_set_arp_speed+0x8a>
mov    -0x4(%rbp),%esi
lea    0xe40(%rip),%rdi
call   1030 <log_error@plt>
jmp    11de <seq_ctrl_set_arp_speed+0x9e>
mov    $0x0,%al
call   1050 <seq_engine_get_current_scene@plt>
mov    %eax,%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <song_set_arp_speed@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seq_ctrl_set_arp_speed>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %esi,%edi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <seq_utils_clamp@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%ebp
je     1177 <seq_ctrl_set_arp_speed+0x37>
cmp    $0x6,%ebp
jb     11ed <seq_ctrl_set_arp_speed+0xad>
lea    0xe96(%rip),%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <log_error@plt>
xor    %eax,%eax
call   1050 <seq_engine_get_current_scene@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <song_set_arp_speed@plt>
xor    %eax,%eax
call   1050 <seq_engine_get_current_scene@plt>
mov    %eax,%edi
mov    $0x1,%esi
mov    %ebx,%edx
call   1040 <song_set_arp_speed@plt>
xor    %eax,%eax
call   1050 <seq_engine_get_current_scene@plt>
mov    %eax,%edi
mov    $0x2,%esi
mov    %ebx,%edx
call   1040 <song_set_arp_speed@plt>
xor    %eax,%eax
call   1050 <seq_engine_get_current_scene@plt>
mov    %eax,%edi
mov    $0x3,%esi
mov    %ebx,%edx
call   1040 <song_set_arp_speed@plt>
xor    %eax,%eax
call   1050 <seq_engine_get_current_scene@plt>
mov    %eax,%edi
mov    $0x4,%esi
mov    %ebx,%edx
call   1040 <song_set_arp_speed@plt>
xor    %eax,%eax
call   1050 <seq_engine_get_current_scene@plt>
mov    %eax,%edi
mov    $0x5,%esi
jmp    11f8 <seq_ctrl_set_arp_speed+0xb8>
xor    %eax,%eax
call   1050 <seq_engine_get_current_scene@plt>
mov    %eax,%edi
mov    %ebp,%esi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <song_set_arp_speed@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"scsas - track invalid: %d\00"
define void @seq_ctrl_set_arp_speed(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call i32 @seq_utils_clamp(i32 %7, i32 0, i32 16)
store i32 %8, i32* %6
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %24
11: ; preds = %2
store i32 0, i32* %5
br label %12
12: ; preds = %20, %11
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 6
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = call i32 (...) @seq_engine_get_current_scene()
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 @song_set_arp_speed(i32 %16, i32 %17, i32 %18)
br label %20
20: ; preds = %15
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %12
23: ; preds = %12
br label %38
24: ; preds = %2
%25 = load i32, i32* %3
%26 = icmp slt i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* %3
%29 = icmp sge i32 %28, 6
br i1 %29, label %30, label %33
30: ; preds = %27, %24
%31 = load i32, i32* %3
%32 = call i32 @log_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %38
33: ; preds = %27
%34 = call i32 (...) @seq_engine_get_current_scene()
%35 = load i32, i32* %3
%36 = load i32, i32* %6
%37 = call i32 @song_set_arp_speed(i32 %34, i32 %35, i32 %36)
br label %38
38: ; preds = %30, %33, %23
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"scsas - track invalid: %d\00"
define void @seq_ctrl_set_arp_speed(i32 %0, i32 %1) {
%3 = tail call i32 @seq_utils_clamp(i32 %1, i32 0, i32 16)
%4 = icmp eq i32 %0, -1
br i1 %4, label %5, label %18
5: ; preds = %2
%6 = tail call i32 (...) @seq_engine_get_current_scene()
%7 = tail call i32 @song_set_arp_speed(i32 %6, i32 0, i32 %3)
%8 = tail call i32 (...) @seq_engine_get_current_scene()
%9 = tail call i32 @song_set_arp_speed(i32 %8, i32 1, i32 %3)
%10 = tail call i32 (...) @seq_engine_get_current_scene()
%11 = tail call i32 @song_set_arp_speed(i32 %10, i32 2, i32 %3)
%12 = tail call i32 (...) @seq_engine_get_current_scene()
%13 = tail call i32 @song_set_arp_speed(i32 %12, i32 3, i32 %3)
%14 = tail call i32 (...) @seq_engine_get_current_scene()
%15 = tail call i32 @song_set_arp_speed(i32 %14, i32 4, i32 %3)
%16 = tail call i32 (...) @seq_engine_get_current_scene()
%17 = tail call i32 @song_set_arp_speed(i32 %16, i32 5, i32 %3)
br label %25
18: ; preds = %2
%19 = icmp ugt i32 %0, 5
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = tail call i32 @log_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %25
22: ; preds = %18
%23 = tail call i32 (...) @seq_engine_get_current_scene()
%24 = tail call i32 @song_set_arp_speed(i32 %23, i32 %0, i32 %3)
br label %25
25: ; preds = %5, %22, %20
ret void
}