#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);
scalar_t__ seq_ctrl_get_track_select(int);
int /*<<< orphan*/ seq_engine_stop_notes(int);
int seq_utils_clamp(int, int, int);
int song_get_midi_port_map(int, int);
int /*<<< orphan*/ song_set_midi_port_map(int, int, int);
void seq_ctrl_adjust_midi_port(int mapnum, int change) {
  int val, track;
  if (mapnum < 0 || mapnum >= 2) {
    log_error("scamp - mapnum invalid: %d", mapnum);
    return;
  }
  for (track = 0; track < 6; track++) {
    if (seq_ctrl_get_track_select(track)) {
      val = seq_utils_clamp(song_get_midi_port_map(track, mapnum) + change, -1,
                            (5 - 1));
      if (val != song_get_midi_port_map(track, mapnum)) {
        seq_engine_stop_notes(track);
        song_set_midi_port_map(track, mapnum, val);
      }
    }
  }
}


x86 assembly (clang, -O0):
<seq_ctrl_adjust_midi_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1182 <seq_ctrl_adjust_midi_port+0x22>
cmpl   $0x2,-0x4(%rbp)
jl     1196 <seq_ctrl_adjust_midi_port+0x36>
mov    -0x4(%rbp),%esi
lea    0xe74(%rip),%rdi
call   1050 <log_error@plt>
jmp    1227 <seq_ctrl_adjust_midi_port+0xc7>
movl   $0x0,-0x10(%rbp)
cmpl   $0x6,-0x10(%rbp)
jge    1227 <seq_ctrl_adjust_midi_port+0xc7>
mov    -0x10(%rbp),%edi
call   1070 <seq_ctrl_get_track_select@plt>
cmp    $0x0,%rax
je     1214 <seq_ctrl_adjust_midi_port+0xb4>
mov    -0x10(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <song_get_midi_port_map@plt>
mov    %eax,%edi
add    -0x8(%rbp),%edi
mov    $0xffffffff,%esi
mov    $0x4,%edx
call   1080 <seq_utils_clamp@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <song_get_midi_port_map@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
je     120f <seq_ctrl_adjust_midi_port+0xaf>
mov    -0x10(%rbp),%edi
call   1060 <seq_engine_stop_notes@plt>
mov    -0x10(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <song_set_midi_port_map@plt>
jmp    1214 <seq_ctrl_adjust_midi_port+0xb4>
jmp    1219 <seq_ctrl_adjust_midi_port+0xb9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119d <seq_ctrl_adjust_midi_port+0x3d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seq_ctrl_adjust_midi_port>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
cmp    $0x1,%edi
jbe    1188 <seq_ctrl_adjust_midi_port+0x28>
lea    0xe8a(%rip),%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <log_error@plt>
mov    %esi,%r14d
xor    %ebp,%ebp
jmp    1198 <seq_ctrl_adjust_midi_port+0x38>
nop
add    $0x1,%ebp
cmp    $0x6,%ebp
je     11e6 <seq_ctrl_adjust_midi_port+0x86>
mov    %ebp,%edi
call   1070 <seq_ctrl_get_track_select@plt>
test   %rax,%rax
je     1190 <seq_ctrl_adjust_midi_port+0x30>
mov    %ebp,%edi
mov    %r15d,%esi
call   1040 <song_get_midi_port_map@plt>
lea    (%rax,%r14,1),%edi
mov    $0xffffffff,%esi
mov    $0x4,%edx
call   1080 <seq_utils_clamp@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r15d,%esi
call   1040 <song_get_midi_port_map@plt>
cmp    %eax,%ebx
je     1190 <seq_ctrl_adjust_midi_port+0x30>
mov    %ebp,%edi
call   1060 <seq_engine_stop_notes@plt>
mov    %ebp,%edi
mov    %r15d,%esi
mov    %ebx,%edx
call   1030 <song_set_midi_port_map@plt>
jmp    1190 <seq_ctrl_adjust_midi_port+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"scamp - mapnum invalid: %d\00"
define void @seq_ctrl_adjust_midi_port(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* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %9, %2
%13 = load i32, i32* %3
%14 = call i32 @log_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %47
15: ; preds = %9
store i32 0, i32* %6
br label %16
16: ; preds = %44, %15
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 6
br i1 %18, label %19, label %47
19: ; preds = %16
%20 = load i32, i32* %6
%21 = call i64 @seq_ctrl_get_track_select(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %43
23: ; preds = %19
%24 = load i32, i32* %6
%25 = load i32, i32* %3
%26 = call i32 @song_get_midi_port_map(i32 %24, i32 %25)
%27 = load i32, i32* %4
%28 = add nsw i32 %26, %27
%29 = call i32 @seq_utils_clamp(i32 %28, i32 -1, i32 4)
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = load i32, i32* %3
%33 = call i32 @song_get_midi_port_map(i32 %31, i32 %32)
%34 = icmp ne i32 %30, %33
br i1 %34, label %35, label %42
35: ; preds = %23
%36 = load i32, i32* %6
%37 = call i32 @seq_engine_stop_notes(i32 %36)
%38 = load i32, i32* %6
%39 = load i32, i32* %3
%40 = load i32, i32* %5
%41 = call i32 @song_set_midi_port_map(i32 %38, i32 %39, i32 %40)
br label %42
42: ; preds = %35, %23
br label %43
43: ; preds = %42, %19
br label %44
44: ; preds = %43
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %16
47: ; preds = %12, %16
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"scamp - mapnum invalid: %d\00"
define void @seq_ctrl_adjust_midi_port(i32 %0, i32 %1) {
%3 = icmp ugt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @log_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %22
6: ; preds = %2, %19
%7 = phi i32 [ %20, %19 ], [ 0, %2 ]
%8 = tail call i64 @seq_ctrl_get_track_select(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = tail call i32 @song_get_midi_port_map(i32 %7, i32 %0)
%12 = add nsw i32 %11, %1
%13 = tail call i32 @seq_utils_clamp(i32 %12, i32 -1, i32 4)
%14 = tail call i32 @song_get_midi_port_map(i32 %7, i32 %0)
%15 = icmp eq i32 %13, %14
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = tail call i32 @seq_engine_stop_notes(i32 %7)
%18 = tail call i32 @song_set_midi_port_map(i32 %7, i32 %0, i32 %13)
br label %19
19: ; preds = %6, %16, %10
%20 = add nuw nsw i32 %7, 1
%21 = icmp eq i32 %20, 6
br i1 %21, label %22, label %6
22: ; preds = %19, %4
ret void
}