#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 */
scalar_t__ get_order_plus_one_from_channels(int, int *);
int get_streams_from_channels(int channels, int mapping_family, int *streams,
                              int *coupled_streams, int *order_plus_one) {
  if (mapping_family == 3) {
    if (get_order_plus_one_from_channels(channels, order_plus_one) != 0)
      return -1;
    if (streams)
      *streams = (channels + 1) / 2;
    if (coupled_streams)
      *coupled_streams = channels / 2;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_streams_from_channels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpl   $0x3,-0xc(%rbp)
jne    11a1 <get_streams_from_channels+0x91>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <get_order_plus_one_from_channels@plt>
cmp    $0x0,%rax
je     1156 <get_streams_from_channels+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <get_streams_from_channels+0x98>
cmpq   $0x0,-0x18(%rbp)
je     1177 <get_streams_from_channels+0x67>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1195 <get_streams_from_channels+0x85>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11a8 <get_streams_from_channels+0x98>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_streams_from_channels>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
cmp    $0x3,%esi
jne    115e <get_streams_from_channels+0x4e>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %edi,%ebx
mov    %r8,%rsi
call   1030 <get_order_plus_one_from_channels@plt>
test   %rax,%rax
jne    115e <get_streams_from_channels+0x4e>
test   %r15,%r15
je     114b <get_streams_from_channels+0x3b>
lea    0x1(%rbx),%eax
shr    $0x1f,%eax
add    %ebx,%eax
add    $0x1,%eax
sar    %eax
mov    %eax,(%r15)
xor    %ebp,%ebp
test   %r14,%r14
je     115e <get_streams_from_channels+0x4e>
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
mov    %eax,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @get_streams_from_channels(i32 %0, i32 %1, i32* writeonly %2, i32* writeonly %3, i32* %4) {
%6 = icmp eq i32 %1, 3
br i1 %6, label %7, label %19
7: ; preds = %5
%8 = tail call i64 @get_order_plus_one_from_channels(i32 %0, i32* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = icmp eq i32* %2, null
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = add nsw i32 %0, 1
%14 = sdiv i32 %13, 2
store i32 %14, i32* %2
br label %15
15: ; preds = %12, %10
%16 = icmp eq i32* %3, null
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = sdiv i32 %0, 2
store i32 %18, i32* %3
br label %19
19: ; preds = %5, %15, %17, %7
%20 = phi i32 [ -1, %7 ], [ 0, %17 ], [ 0, %15 ], [ -1, %5 ]
ret i32 %20
}