#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 isqrt32(int);
int get_order_plus_one_from_channels(int channels, int *order_plus_one) {
  int order_plus_one_;
  int acn_channels;
  int nondiegetic_channels;
  if (channels < 1 || channels > 227)
    return -1;
  order_plus_one_ = isqrt32(channels);
  acn_channels = order_plus_one_ * order_plus_one_;
  nondiegetic_channels = channels - acn_channels;
  if (nondiegetic_channels != 0 && nondiegetic_channels != 2)
    return -1;
  if (order_plus_one)
    *order_plus_one = order_plus_one_;
  return 0;
}


x86 assembly (clang, -O0):
<get_order_plus_one_from_channels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     1136 <get_order_plus_one_from_channels+0x26>
cmpl   $0xe3,-0x8(%rbp)
jle    1142 <get_order_plus_one_from_channels+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <get_order_plus_one_from_channels+0x8b>
mov    -0x8(%rbp),%edi
call   1030 <isqrt32@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1180 <get_order_plus_one_from_channels+0x70>
cmpl   $0x2,-0x1c(%rbp)
je     1180 <get_order_plus_one_from_channels+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <get_order_plus_one_from_channels+0x8b>
cmpq   $0x0,-0x10(%rbp)
je     1194 <get_order_plus_one_from_channels+0x84>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_order_plus_one_from_channels>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    -0xe4(%rbx),%eax
mov    $0xffffffff,%ebp
cmp    $0xffffff1d,%eax
jb     114b <get_order_plus_one_from_channels+0x3b>
mov    %rsi,%r14
mov    %ebx,%edi
call   1030 <isqrt32@plt>
mov    %eax,%ecx
imul   %eax,%ecx
sub    %ecx,%ebx
test   $0xfffffffd,%ebx
jne    114b <get_order_plus_one_from_channels+0x3b>
xor    %ebp,%ebp
test   %r14,%r14
je     114b <get_order_plus_one_from_channels+0x3b>
mov    %eax,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_order_plus_one_from_channels(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 227
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store i32 -1, i32* %3
br label %37
15: ; preds = %11
%16 = load i32, i32* %4
%17 = call i32 @isqrt32(i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = load i32, i32* %6
%20 = mul nsw i32 %18, %19
store i32 %20, i32* %7
%21 = load i32, i32* %4
%22 = load i32, i32* %7
%23 = sub nsw i32 %21, %22
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %15
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 2
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 -1, i32* %3
br label %37
30: ; preds = %26, %15
%31 = load i32*, i32** %5
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %6
%35 = load i32*, i32** %5
store i32 %34, i32* %35
br label %36
36: ; preds = %33, %30
store i32 0, i32* %3
br label %37
37: ; preds = %36, %29, %14
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @get_order_plus_one_from_channels(i32 %0, i32* writeonly %1) {
%3 = add i32 %0, -228
%4 = icmp ult i32 %3, -227
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i32 @isqrt32(i32 %0)
%7 = mul nsw i32 %6, %6
%8 = sub nsw i32 %0, %7
%9 = and i32 %8, -3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = icmp eq i32* %1, null
br i1 %12, label %14, label %13
13: ; preds = %11
store i32 %6, i32* %1
br label %14
14: ; preds = %11, %13, %5, %2
%15 = phi i32 [ -1, %2 ], [ -1, %5 ], [ 0, %13 ], [ 0, %11 ]
ret i32 %15
}