#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 gsm0710_context {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ gsm0710_write_frame(struct gsm0710_context *, int, int,
                                       int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ is_channel_used(struct gsm0710_context *, int);
int /*<<< orphan*/ mark_channel_used(struct gsm0710_context *, int);
int gsm0710_open_channel(struct gsm0710_context *ctx, int channel) {
  if (channel <= 0 || channel > 63)
    return 0;
  if (is_channel_used(ctx, channel))
    return 1;
  mark_channel_used(ctx, channel);
  gsm0710_write_frame(ctx, channel, 0x3F, 0, 0);
  return 1;
}


x86 assembly (clang, -O0):
<gsm0710_open_channel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1153 <gsm0710_open_channel+0x23>
cmpl   $0x3f,-0x14(%rbp)
jle    115f <gsm0710_open_channel+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    11ab <gsm0710_open_channel+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <is_channel_used@plt>
cmp    $0x0,%rax
je     1181 <gsm0710_open_channel+0x51>
movl   $0x1,-0x4(%rbp)
jmp    11ab <gsm0710_open_channel+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <mark_channel_used@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x3f,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1040 <gsm0710_write_frame@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsm0710_open_channel>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
lea    -0x40(%rbx),%eax
xor    %ebp,%ebp
cmp    $0xffffffc1,%eax
jb     1172 <gsm0710_open_channel+0x42>
mov    %rdi,%r14
mov    %ebx,%esi
call   1050 <is_channel_used@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1172 <gsm0710_open_channel+0x42>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <mark_channel_used@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x3f,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <gsm0710_write_frame@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.gsm0710_context = type { i32 }
define i32 @gsm0710_open_channel(%struct.gsm0710_context* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.gsm0710_context*
%5 = alloca i32
store %struct.gsm0710_context* %0, %struct.gsm0710_context** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp sle i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 63
br i1 %10, label %11, label %12
11: ; preds = %8, %2
store i32 0, i32* %3
br label %25
12: ; preds = %8
%13 = load %struct.gsm0710_context*, %struct.gsm0710_context** %4
%14 = load i32, i32* %5
%15 = call i64 @is_channel_used(%struct.gsm0710_context* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 1, i32* %3
br label %25
18: ; preds = %12
%19 = load %struct.gsm0710_context*, %struct.gsm0710_context** %4
%20 = load i32, i32* %5
%21 = call i32 @mark_channel_used(%struct.gsm0710_context* %19, i32 %20)
%22 = load %struct.gsm0710_context*, %struct.gsm0710_context** %4
%23 = load i32, i32* %5
%24 = call i32 @gsm0710_write_frame(%struct.gsm0710_context* %22, i32 %23, i32 63, i32 0, i32 0)
store i32 1, i32* %3
br label %25
25: ; preds = %18, %17, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.gsm0710_context = type { i32 }
define i32 @gsm0710_open_channel(%struct.gsm0710_context* %0, i32 %1) {
%3 = add i32 %1, -64
%4 = icmp ult i32 %3, -63
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i64 @is_channel_used(%struct.gsm0710_context* %0, i32 %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @mark_channel_used(%struct.gsm0710_context* %0, i32 %1)
%10 = tail call i32 @gsm0710_write_frame(%struct.gsm0710_context* %0, i32 %1, i32 63, i32 0, i32 0)
br label %11
11: ; preds = %5, %2, %8
%12 = phi i32 [ 1, %8 ], [ 0, %2 ], [ 1, %5 ]
ret i32 %12
}