#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 */
struct opna_ssg {
  int dummy;
};

/* Variables and functions */
scalar_t__ opna_ssg_chan_env(struct opna_ssg const *, int);
int opna_ssg_env_level(struct opna_ssg const *);
int opna_ssg_tone_volume(struct opna_ssg const *, int);
int opna_ssg_channel_level(const struct opna_ssg *ssg, int ch) {
  return opna_ssg_chan_env(ssg, ch) ? opna_ssg_env_level(ssg)
                                    : (opna_ssg_tone_volume(ssg, ch) << 1) + 1;
}


x86 assembly (clang, -O0):
<opna_ssg_channel_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <opna_ssg_chan_env@plt>
cmp    $0x0,%rax
je     1166 <opna_ssg_channel_level+0x36>
mov    -0x8(%rbp),%rdi
call   1050 <opna_ssg_env_level@plt>
mov    %eax,-0x10(%rbp)
jmp    117b <opna_ssg_channel_level+0x4b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <opna_ssg_tone_volume@plt>
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opna_ssg_channel_level>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <opna_ssg_chan_env@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     1150 <opna_ssg_channel_level+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <opna_ssg_env_level@plt>
mov    %ebp,%esi
call   1040 <opna_ssg_tone_volume@plt>
add    %eax,%eax
add    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.opna_ssg = type { i32 }
define i32 @opna_ssg_channel_level(%struct.opna_ssg* %0, i32 %1) {
%3 = alloca %struct.opna_ssg*
%4 = alloca i32
store %struct.opna_ssg* %0, %struct.opna_ssg** %3
store i32 %1, i32* %4
%5 = load %struct.opna_ssg*, %struct.opna_ssg** %3
%6 = load i32, i32* %4
%7 = call i64 @opna_ssg_chan_env(%struct.opna_ssg* %5, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load %struct.opna_ssg*, %struct.opna_ssg** %3
%11 = call i32 @opna_ssg_env_level(%struct.opna_ssg* %10)
br label %18
12: ; preds = %2
%13 = load %struct.opna_ssg*, %struct.opna_ssg** %3
%14 = load i32, i32* %4
%15 = call i32 @opna_ssg_tone_volume(%struct.opna_ssg* %13, i32 %14)
%16 = shl i32 %15, 1
%17 = add nsw i32 %16, 1
br label %18
18: ; preds = %12, %9
%19 = phi i32 [ %11, %9 ], [ %17, %12 ]
ret i32 %19
}

LLVM IR (-O2):
%struct.opna_ssg = type { i32 }
define i32 @opna_ssg_channel_level(%struct.opna_ssg* %0, i32 %1) {
%3 = tail call i64 @opna_ssg_chan_env(%struct.opna_ssg* %0, i32 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @opna_ssg_env_level(%struct.opna_ssg* %0)
br label %11
7: ; preds = %2
%8 = tail call i32 @opna_ssg_tone_volume(%struct.opna_ssg* %0, i32 %1)
%9 = shl i32 %8, 1
%10 = or i32 %9, 1
br label %11
11: ; preds = %7, %5
%12 = phi i32 [ %6, %5 ], [ %10, %7 ]
ret i32 %12
}