void switch_info(unsigned inputs, unsigned *n_switches, unsigned *depth) {
  if (inputs == 0) {
    *depth = 0;
    *n_switches = 0;
  } else if (inputs == 1) {
    *depth = 0;
    *n_switches = 0;
  } else if (inputs == 2) {
    *depth = 1;
    *n_switches = 1;
  } else {
    unsigned a, b;
    a = inputs / 2;
    b = a + inputs % 2;
    unsigned a1, b1;
    unsigned depth_a, depth_b;
    switch_info(a, &a1, &depth_a);
    switch_info(b, &b1, &depth_b);
    *depth = 2 + (depth_a > depth_b ? depth_a : depth_b);
    *n_switches = 2 * (inputs / 2) + a1 + b1;
  }
}


x86 assembly (clang, -O0):
<switch_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1146 <switch_info+0x36>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    120b <switch_info+0xfb>
cmpl   $0x1,-0x4(%rbp)
jne    1169 <switch_info+0x59>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    1206 <switch_info+0xf6>
cmpl   $0x2,-0x4(%rbp)
jne    118c <switch_info+0x7c>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    1201 <switch_info+0xf1>
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4(%rbp),%ecx
and    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x24(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1030 <switch_info@plt>
mov    -0x20(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <switch_info@plt>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jbe    11da <switch_info+0xca>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    11e0 <switch_info+0xd0>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
add    $0x2,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%ecx
shr    $0x1,%ecx
shl    $0x1,%ecx
add    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1206 <switch_info+0xf6>
jmp    120b <switch_info+0xfb>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<switch_info>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
cmp    $0x2,%edi
je     1140 <switch_info+0x30>
mov    %edi,%ebp
cmp    $0x1,%edi
je     1130 <switch_info+0x20>
test   %ebp,%ebp
jne    1150 <switch_info+0x40>
movl   $0x0,(%r15)
movl   $0x0,(%r14)
jmp    119c <switch_info+0x8c>
movl   $0x1,(%r15)
movl   $0x1,(%r14)
jmp    119c <switch_info+0x8c>
mov    %ebp,%edi
shr    %edi
mov    %ebp,%ebx
and    $0x1,%ebx
add    %edi,%ebx
lea    0x14(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1030 <switch_info@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <switch_info@plt>
mov    0xc(%rsp),%eax
mov    0x8(%rsp),%ecx
cmp    %ecx,%eax
cmova  %eax,%ecx
add    $0x2,%ecx
mov    %ecx,(%r15)
and    $0xfffffffe,%ebp
add    0x14(%rsp),%ebp
add    0x10(%rsp),%ebp
mov    %ebp,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @switch_info(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32*, i32** %6
store i32 0, i32* %16
%17 = load i32*, i32** %5
store i32 0, i32* %17
br label %60
18: ; preds = %3
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32*, i32** %6
store i32 0, i32* %22
%23 = load i32*, i32** %5
store i32 0, i32* %23
br label %59
24: ; preds = %18
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32*, i32** %6
store i32 1, i32* %28
%29 = load i32*, i32** %5
store i32 1, i32* %29
br label %58
30: ; preds = %24
%31 = load i32, i32* %4
%32 = udiv i32 %31, 2
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = load i32, i32* %4
%35 = urem i32 %34, 2
%36 = add i32 %33, %35
store i32 %36, i32* %8
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = load i32, i32* %11
%40 = load i32, i32* %12
%41 = icmp ugt i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %30
%43 = load i32, i32* %11
br label %46
44: ; preds = %30
%45 = load i32, i32* %12
br label %46
46: ; preds = %44, %42
%47 = phi i32 [ %43, %42 ], [ %45, %44 ]
%48 = add i32 2, %47
%49 = load i32*, i32** %6
store i32 %48, i32* %49
%50 = load i32, i32* %4
%51 = udiv i32 %50, 2
%52 = mul i32 2, %51
%53 = load i32, i32* %9
%54 = add i32 %52, %53
%55 = load i32, i32* %10
%56 = add i32 %54, %55
%57 = load i32*, i32** %5
store i32 %56, i32* %57
br label %58
58: ; preds = %46, %27
br label %59
59: ; preds = %58, %21
br label %60
60: ; preds = %59, %15
ret void
}

LLVM IR (-O2):
define void @switch_info(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
switch i32 %0, label %11 [
i32 0, label %8
i32 1, label %9
i32 2, label %10
]
8: ; preds = %3
store i32 0, i32* %2
store i32 0, i32* %1
br label %29
9: ; preds = %3
store i32 0, i32* %2
store i32 0, i32* %1
br label %29
10: ; preds = %3
store i32 1, i32* %2
store i32 1, i32* %1
br label %29
11: ; preds = %3
%12 = lshr i32 %0, 1
%13 = and i32 %0, 1
%14 = add nuw i32 %12, %13
%15 = bitcast i32* %4 to i8*
%16 = bitcast i32* %5 to i8*
%17 = bitcast i32* %6 to i8*
%18 = bitcast i32* %7 to i8*
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = icmp ugt i32 %19, %20
%22 = select i1 %21, i32 %19, i32 %20
%23 = add i32 %22, 2
store i32 %23, i32* %2
%24 = and i32 %0, -2
%25 = load i32, i32* %4
%26 = add i32 %25, %24
%27 = load i32, i32* %5
%28 = add i32 %26, %27
store i32 %28, i32* %1
br label %29
29: ; preds = %9, %11, %10, %8
ret void
}