#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(int, int, int);
int song_get_midi_port_map(int, int);
int /*<<< orphan*/ song_set_midi_program(int, int, int /*<<< orphan*/);
void seq_ctrl_set_midi_program(int track, int mapnum, int program) {
  if (track < 0 || track >= 6) {
    log_error("scsmp - track invalid: %d", track);
    return;
  }
  if (mapnum < 0 || mapnum >= 2) {
    log_error("scsmp - mapnum invalid: %d", mapnum);
    return;
  }
  if (song_get_midi_port_map(track, mapnum) == 2) {
    return;
  }
  song_set_midi_program(track, mapnum, seq_utils_clamp(program, -1, 0x7f));
}


x86 assembly (clang, -O0):
<seq_ctrl_set_midi_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1165 <seq_ctrl_set_midi_program+0x25>
cmpl   $0x6,-0x4(%rbp)
jl     1179 <seq_ctrl_set_midi_program+0x39>
mov    -0x4(%rbp),%esi
lea    0xe91(%rip),%rdi
call   1040 <log_error@plt>
jmp    11e5 <seq_ctrl_set_midi_program+0xa5>
cmpl   $0x0,-0x8(%rbp)
jl     118d <seq_ctrl_set_midi_program+0x4d>
cmpl   $0x2,-0x8(%rbp)
jl     11a1 <seq_ctrl_set_midi_program+0x61>
mov    -0x8(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1040 <log_error@plt>
jmp    11e5 <seq_ctrl_set_midi_program+0xa5>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <song_get_midi_port_map@plt>
cmp    $0x2,%eax
jne    11ba <seq_ctrl_set_midi_program+0x7a>
jmp    11e5 <seq_ctrl_set_midi_program+0xa5>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    $0xffffffff,%esi
mov    $0x7f,%edx
call   1060 <seq_utils_clamp@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    %eax,%edx
call   1050 <song_set_midi_program@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seq_ctrl_set_midi_program>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
cmp    $0x6,%edi
jb     1156 <seq_ctrl_set_midi_program+0x16>
lea    0xeae(%rip),%rdi
mov    %ebp,%esi
jmp    1166 <seq_ctrl_set_midi_program+0x26>
mov    %esi,%ebx
cmp    $0x2,%esi
jb     116f <seq_ctrl_set_midi_program+0x2f>
lea    0xeb6(%rip),%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <log_error@plt>
mov    %edx,%r14d
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <song_get_midi_port_map@plt>
cmp    $0x2,%eax
jne    1185 <seq_ctrl_set_midi_program+0x45>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14d,%edi
mov    $0xffffffff,%esi
mov    $0x7f,%edx
call   1060 <seq_utils_clamp@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <song_set_midi_program@plt>

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

LLVM IR (-O2):
@.str = [26 x i8] c"scsmp - track invalid: %d\00"
@.str.1 = [27 x i8] c"scsmp - mapnum invalid: %d\00"
define void @seq_ctrl_set_midi_program(i32 %0, i32 %1, i32 %2) {
%4 = icmp ugt i32 %0, 5
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @log_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %17
7: ; preds = %3
%8 = icmp ugt i32 %1, 1
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @log_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %17
11: ; preds = %7
%12 = tail call i32 @song_get_midi_port_map(i32 %0, i32 %1)
%13 = icmp eq i32 %12, 2
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @seq_utils_clamp(i32 %2, i32 -1, i32 127)
%16 = tail call i32 @song_set_midi_program(i32 %0, i32 %1, i32 %15)
br label %17
17: ; preds = %11, %14, %9, %5
ret void
}