#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 */
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ IPV6_RTHDR_TYPE_0;
int /*<<< orphan*/ checknum(int /*<<< orphan*/, int /*<<< orphan*/, int,
                            char *);
int /*<<< orphan*/ inet6_rth_space(int /*<<< orphan*/, int);
int /*<<< orphan*/ set_funcname(char *, int);
void test_rth_space() {
  socklen_t len;
  set_funcname("test_rth_space", sizeof("test_rth_space\0"));
  len = inet6_rth_space(~IPV6_RTHDR_TYPE_0, 0);
  checknum(0, len, 0, "invalid routing header type\0");
  len = inet6_rth_space(IPV6_RTHDR_TYPE_0, 0);
  checknum(0, len, 1, "0 segments\0");
  len = inet6_rth_space(IPV6_RTHDR_TYPE_0, 127);
  checknum(0, len, 1, "0 segments\0");
  len = inet6_rth_space(IPV6_RTHDR_TYPE_0, -1);
  checknum(0, len, 0, "-1 segments\0");
  len = inet6_rth_space(IPV6_RTHDR_TYPE_0, 128);
  checknum(0, len, 0, "128 segments\0");
}


x86 assembly (clang, -O0):
<test_rth_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
mov    $0x10,%esi
call   1050 <set_funcname@plt>
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
xor    $0xffffffff,%edi
xor    %esi,%esi
call   1030 <inet6_rth_space@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
xor    %edx,%edx
lea    0xea4(%rip),%rcx
mov    %edx,%edi
call   1040 <checknum@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <inet6_rth_space@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
xor    %edi,%edi
mov    $0x1,%edx
lea    0xe96(%rip),%rcx
call   1040 <checknum@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    $0x7f,%esi
call   1030 <inet6_rth_space@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
xor    %edi,%edi
mov    $0x1,%edx
lea    0xe6a(%rip),%rcx
call   1040 <checknum@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
call   1030 <inet6_rth_space@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
xor    %edx,%edx
lea    0xe4f(%rip),%rcx
mov    %edx,%edi
call   1040 <checknum@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    $0x80,%esi
call   1030 <inet6_rth_space@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
xor    %edx,%edx
lea    0xe33(%rip),%rcx
mov    %edx,%edi
call   1040 <checknum@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rth_space>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
mov    $0x10,%esi
call   1050 <set_funcname@plt>
mov    0x2e9c(%rip),%r14
mov    (%r14),%edi
not    %edi
xor    %esi,%esi
call   1030 <inet6_rth_space@plt>
lea    0xeb0(%rip),%rcx
xor    %edi,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <checknum@plt>
mov    (%r14),%edi
xor    %esi,%esi
call   1030 <inet6_rth_space@plt>
lea    0xeb1(%rip),%rbx
xor    %edi,%edi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <checknum@plt>
mov    (%r14),%edi
mov    $0x7f,%esi
call   1030 <inet6_rth_space@plt>
xor    %edi,%edi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <checknum@plt>
mov    (%r14),%edi
mov    $0xffffffff,%esi
call   1030 <inet6_rth_space@plt>
lea    0xe7a(%rip),%rcx
xor    %edi,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <checknum@plt>
mov    (%r14),%edi
mov    $0x80,%esi
call   1030 <inet6_rth_space@plt>
lea    0xe68(%rip),%rcx
xor    %edi,%edi
mov    %eax,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <checknum@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"test_rth_space\00"
@IPV6_RTHDR_TYPE_0 = global i32 0
@.str.1 = [29 x i8] c"invalid routing header type\00\00"
@.str.2 = [12 x i8] c"0 segments\00\00"
@.str.3 = [13 x i8] c"-1 segments\00\00"
@.str.4 = [14 x i8] c"128 segments\00\00"
define void @test_rth_space() {
%1 = alloca i32
%2 = call i32 @set_funcname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 16)
%3 = load i32, i32* @IPV6_RTHDR_TYPE_0
%4 = xor i32 %3, -1
%5 = call i32 @inet6_rth_space(i32 %4, i32 0)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = call i32 @checknum(i32 0, i32 %6, i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @IPV6_RTHDR_TYPE_0
%9 = call i32 @inet6_rth_space(i32 %8, i32 0)
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = call i32 @checknum(i32 0, i32 %10, i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @IPV6_RTHDR_TYPE_0
%13 = call i32 @inet6_rth_space(i32 %12, i32 127)
store i32 %13, i32* %1
%14 = load i32, i32* %1
%15 = call i32 @checknum(i32 0, i32 %14, i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @IPV6_RTHDR_TYPE_0
%17 = call i32 @inet6_rth_space(i32 %16, i32 -1)
store i32 %17, i32* %1
%18 = load i32, i32* %1
%19 = call i32 @checknum(i32 0, i32 %18, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @IPV6_RTHDR_TYPE_0
%21 = call i32 @inet6_rth_space(i32 %20, i32 128)
store i32 %21, i32* %1
%22 = load i32, i32* %1
%23 = call i32 @checknum(i32 0, i32 %22, i32 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"test_rth_space\00"
@IPV6_RTHDR_TYPE_0 = global i32 0
@.str.1 = [29 x i8] c"invalid routing header type\00\00"
@.str.2 = [12 x i8] c"0 segments\00\00"
@.str.3 = [13 x i8] c"-1 segments\00\00"
@.str.4 = [14 x i8] c"128 segments\00\00"
define void @test_rth_space() {
%1 = tail call i32 @set_funcname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 16)
%2 = load i32, i32* @IPV6_RTHDR_TYPE_0
%3 = xor i32 %2, -1
%4 = tail call i32 @inet6_rth_space(i32 %3, i32 0)
%5 = tail call i32 @checknum(i32 0, i32 %4, i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @IPV6_RTHDR_TYPE_0
%7 = tail call i32 @inet6_rth_space(i32 %6, i32 0)
%8 = tail call i32 @checknum(i32 0, i32 %7, i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @IPV6_RTHDR_TYPE_0
%10 = tail call i32 @inet6_rth_space(i32 %9, i32 127)
%11 = tail call i32 @checknum(i32 0, i32 %10, i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @IPV6_RTHDR_TYPE_0
%13 = tail call i32 @inet6_rth_space(i32 %12, i32 -1)
%14 = tail call i32 @checknum(i32 0, i32 %13, i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* @IPV6_RTHDR_TYPE_0
%16 = tail call i32 @inet6_rth_space(i32 %15, i32 128)
%17 = tail call i32 @checknum(i32 0, i32 %16, i32 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
ret void
}