#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_ctrl_clear_song();
int /*<<< orphan*/ seq_ctrl_set_record_mode(int /*<<< orphan*/);
int /*<<< orphan*/ seq_ctrl_set_run_lockout(int);
int /*<<< orphan*/ seq_ctrl_set_run_state(int /*<<< orphan*/);
int song_load(int);
int seq_ctrl_load_song(int song) {
  if (song < 0 || song >= 64) {
    log_error("scls - song invalid: %d", song);
    return -1;
  }
  seq_ctrl_set_record_mode(0);
  seq_ctrl_set_run_lockout(1);
  seq_ctrl_set_run_state(0);
  if (song_load(song) == -1) {
    seq_ctrl_clear_song();
  }
  return 0;
}


x86 assembly (clang, -O0):
<seq_ctrl_load_song>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     117f <seq_ctrl_load_song+0x1f>
cmpl   $0x40,-0x8(%rbp)
jl     119a <seq_ctrl_load_song+0x3a>
mov    -0x8(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1030 <log_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <seq_ctrl_load_song+0x71>
xor    %edi,%edi
call   1040 <seq_ctrl_set_record_mode@plt>
mov    $0x1,%edi
call   1070 <seq_ctrl_set_run_lockout@plt>
xor    %edi,%edi
call   1080 <seq_ctrl_set_run_state@plt>
mov    -0x8(%rbp),%edi
call   1060 <song_load@plt>
cmp    $0xffffffff,%eax
jne    11ca <seq_ctrl_load_song+0x6a>
mov    $0x0,%al
call   1050 <seq_ctrl_clear_song@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seq_ctrl_load_song>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
cmp    $0x40,%edi
jb     117f <seq_ctrl_load_song+0x1f>
lea    0xe8f(%rip),%rdi
mov    %ebp,%esi
call   1030 <log_error@plt>
mov    $0xffffffff,%ebx
jmp    11ae <seq_ctrl_load_song+0x4e>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <seq_ctrl_set_record_mode@plt>
mov    $0x1,%edi
call   1070 <seq_ctrl_set_run_lockout@plt>
xor    %edi,%edi
call   1080 <seq_ctrl_set_run_state@plt>
mov    %ebp,%edi
call   1060 <song_load@plt>
cmp    $0xffffffff,%eax
jne    11ae <seq_ctrl_load_song+0x4e>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <seq_ctrl_clear_song@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"scls - song invalid: %d\00"
define i32 @seq_ctrl_load_song(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp sge i32 %7, 64
br i1 %8, label %9, label %12
9: ; preds = %6, %1
%10 = load i32, i32* %3
%11 = call i32 @log_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 -1, i32* %2
br label %22
12: ; preds = %6
%13 = call i32 @seq_ctrl_set_record_mode(i32 0)
%14 = call i32 @seq_ctrl_set_run_lockout(i32 1)
%15 = call i32 @seq_ctrl_set_run_state(i32 0)
%16 = load i32, i32* %3
%17 = call i32 @song_load(i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 (...) @seq_ctrl_clear_song()
br label %21
21: ; preds = %19, %12
store i32 0, i32* %2
br label %22
22: ; preds = %21, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [24 x i8] c"scls - song invalid: %d\00"
define i32 @seq_ctrl_load_song(i32 %0) {
%2 = icmp ugt i32 %0, 63
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @log_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %13
5: ; preds = %1
%6 = tail call i32 @seq_ctrl_set_record_mode(i32 0)
%7 = tail call i32 @seq_ctrl_set_run_lockout(i32 1)
%8 = tail call i32 @seq_ctrl_set_run_state(i32 0)
%9 = tail call i32 @song_load(i32 %0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 (...) @seq_ctrl_clear_song()
br label %13
13: ; preds = %5, %11, %3
%14 = phi i32 [ -1, %3 ], [ 0, %11 ], [ 0, %5 ]
ret i32 %14
}