#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 in6_addr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int IPV6_RTHDR_TYPE_0;
socklen_t inet6_rth_space(int type, int segments) {
  if (type == IPV6_RTHDR_TYPE_0) {
    if (segments > 128)
      return 0;
    return 8 + segments * sizeof(struct in6_addr);
  } else if (type == 2) {
    if (segments != 1)
      return 0;
    return 8 + sizeof(struct in6_addr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<inet6_rth_space>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2ed4(%rip),%rcx
cmp    (%rcx),%eax
jne    1149 <inet6_rth_space+0x49>
cmpl   $0x80,-0xc(%rbp)
jle    1135 <inet6_rth_space+0x35>
movl   $0x0,-0x4(%rbp)
jmp    1181 <inet6_rth_space+0x81>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    $0x8,%rax
mov    %eax,-0x4(%rbp)
jmp    1181 <inet6_rth_space+0x81>
cmpl   $0x2,-0x8(%rbp)
jne    1175 <inet6_rth_space+0x75>
cmpl   $0x1,-0xc(%rbp)
je     1169 <inet6_rth_space+0x69>
movl   $0x0,-0x4(%rbp)
jmp    1181 <inet6_rth_space+0x81>
movl   $0xc,-0x4(%rbp)
jmp    1181 <inet6_rth_space+0x81>
jmp    117a <inet6_rth_space+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_rth_space>:
mov    0x2ee1(%rip),%rax
cmp    %edi,(%rax)
jne    111d <inet6_rth_space+0x1d>
xor    %eax,%eax
cmp    $0x80,%esi
jg     1131 <inet6_rth_space+0x31>
lea    0x8(,%rsi,4),%eax
ret
xor    %eax,%eax
cmp    $0x2,%edi
jne    1131 <inet6_rth_space+0x31>
xor    %ecx,%ecx
cmp    $0x1,%esi
mov    $0xc,%eax
cmovne %ecx,%eax
ret

LLVM IR (-O0):
@IPV6_RTHDR_TYPE_0 = global i32 0
define i32 @inet6_rth_space(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = load i32, i32* @IPV6_RTHDR_TYPE_0
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 128
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 0, i32* %3
br label %29
13: ; preds = %9
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = add i64 8, %16
%18 = trunc i64 %17 to i32
store i32 %18, i32* %3
br label %29
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 0, i32* %3
br label %29
26: ; preds = %22
store i32 12, i32* %3
br label %29
27: ; preds = %19
br label %28
28: ; preds = %27
store i32 0, i32* %3
br label %29
29: ; preds = %28, %26, %25, %13, %12
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@IPV6_RTHDR_TYPE_0 = global i32 0
define i32 @inet6_rth_space(i32 %0, i32 %1) {
%3 = load i32, i32* @IPV6_RTHDR_TYPE_0
%4 = icmp eq i32 %3, %0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = icmp sgt i32 %1, 128
br i1 %6, label %15, label %7
7: ; preds = %5
%8 = shl i32 %1, 2
%9 = add i32 %8, 8
br label %15
10: ; preds = %2
%11 = icmp eq i32 %0, 2
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = icmp eq i32 %1, 1
%14 = select i1 %13, i32 12, i32 0
br label %15
15: ; preds = %10, %12, %5, %7
%16 = phi i32 [ %9, %7 ], [ 0, %5 ], [ %14, %12 ], [ 0, %10 ]
ret i32 %16
}