#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 ip6_rthdr {
  int /*<<< orphan*/ ip6r_type;
};

/* Variables and functions */
int /*<<< orphan*/ IPV6_RTHDR_TYPE_0;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ checknum(int, int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ *inet6_rth_init(void *, int, int /*<<< orphan*/, int);
int inet6_rth_segments(void const *);
int /*<<< orphan*/ set_funcname(char *, int);
void test_rth_segments() {
  int seg;
  char buf[10240];
  set_funcname("test_rth_segments", sizeof("test_rth_segments\0"));
  if (NULL == inet6_rth_init((void *)buf, 10240, IPV6_RTHDR_TYPE_0, 0))
    abort();
  ((struct ip6_rthdr *)buf)->ip6r_type = ~IPV6_RTHDR_TYPE_0;
  seg = inet6_rth_segments((const void *)buf);
  checknum(-1, seg, 0, "invalid routing header type\0");
  if (NULL == inet6_rth_init((void *)buf, 10240, IPV6_RTHDR_TYPE_0, 0))
    abort();
  seg = inet6_rth_segments((const void *)buf);
  checknum(0, seg, 0, "0 segments\0");
  if (NULL == inet6_rth_init((void *)buf, 10240, IPV6_RTHDR_TYPE_0, 127))
    abort();
  seg = inet6_rth_segments((const void *)buf);
  checknum(127, seg, 0, "127 segments\0");
}


x86 assembly (clang, -O0):
<test_rth_segments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2810,%rsp
lea    0xe9e(%rip),%rdi
mov    $0x13,%esi
call   1060 <set_funcname@plt>
lea    -0x2810(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
mov    $0x2800,%esi
xor    %ecx,%ecx
call   1050 <inet6_rth_init@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    119d <test_rth_segments+0x4d>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x2810(%rbp)
lea    -0x2810(%rbp),%rdi
call   1070 <inet6_rth_segments@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    $0xffffffff,%edi
xor    %edx,%edx
lea    0xe43(%rip),%rcx
call   1040 <checknum@plt>
lea    -0x2810(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
mov    $0x2800,%esi
xor    %ecx,%ecx
call   1050 <inet6_rth_init@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1205 <test_rth_segments+0xb5>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x2810(%rbp),%rdi
call   1070 <inet6_rth_segments@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
xor    %edx,%edx
lea    0xe0f(%rip),%rcx
mov    %edx,%edi
call   1040 <checknum@plt>
lea    -0x2810(%rbp),%rdi
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
mov    $0x2800,%esi
mov    $0x7f,%ecx
call   1050 <inet6_rth_init@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    125b <test_rth_segments+0x10b>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x2810(%rbp),%rdi
call   1070 <inet6_rth_segments@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x7f,%edi
xor    %edx,%edx
lea    0xdc0(%rip),%rcx
call   1040 <checknum@plt>
add    $0x2810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rth_segments>:
push   %r14
push   %rbx
sub    $0x2808,%rsp
lea    0xe9f(%rip),%rdi
mov    $0x13,%esi
call   1060 <set_funcname@plt>
mov    0x2e76(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rdi
mov    $0x2800,%esi
xor    %ecx,%ecx
call   1050 <inet6_rth_init@plt>
test   %rax,%rax
je     122b <test_rth_segments+0xdb>
mov    (%r14),%eax
not    %eax
mov    %eax,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <inet6_rth_segments@plt>
lea    0xe6b(%rip),%rcx
mov    $0xffffffff,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <checknum@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x2800,%esi
xor    %ecx,%ecx
call   1050 <inet6_rth_init@plt>
test   %rax,%rax
je     122b <test_rth_segments+0xdb>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <inet6_rth_segments@plt>
lea    0xe51(%rip),%rcx
xor    %edi,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <checknum@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x2800,%esi
mov    $0x7f,%ecx
call   1050 <inet6_rth_init@plt>
test   %rax,%rax
je     122b <test_rth_segments+0xdb>
mov    %rsp,%rdi
call   1070 <inet6_rth_segments@plt>
lea    0xe29(%rip),%rcx
mov    $0x7f,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <checknum@plt>
add    $0x2808,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.ip6_rthdr = type { i32 }
@.str = [18 x i8] c"test_rth_segments\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 = [14 x i8] c"127 segments\00\00"
define void @test_rth_segments() {
%1 = alloca i32
%2 = alloca [10240 x i8]
%3 = call i32 @set_funcname(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 19)
%4 = getelementptr inbounds [10240 x i8], [10240 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @IPV6_RTHDR_TYPE_0
%6 = call i32* @inet6_rth_init(i8* %4, i32 10240, i32 %5, i32 0)
%7 = icmp eq i32* null, %6
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (...) @abort()
unreachable
10: ; preds = %0
%11 = load i32, i32* @IPV6_RTHDR_TYPE_0
%12 = xor i32 %11, -1
%13 = getelementptr inbounds [10240 x i8], [10240 x i8]* %2, i64 0, i64 0
%14 = bitcast i8* %13 to %struct.ip6_rthdr*
%15 = getelementptr inbounds %struct.ip6_rthdr, %struct.ip6_rthdr* %14, i32 0, i32 0
store i32 %12, i32* %15
%16 = getelementptr inbounds [10240 x i8], [10240 x i8]* %2, i64 0, i64 0
%17 = call i32 @inet6_rth_segments(i8* %16)
store i32 %17, i32* %1
%18 = load i32, i32* %1
%19 = call i32 @checknum(i32 -1, i32 %18, i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds [10240 x i8], [10240 x i8]* %2, i64 0, i64 0
%21 = load i32, i32* @IPV6_RTHDR_TYPE_0
%22 = call i32* @inet6_rth_init(i8* %20, i32 10240, i32 %21, i32 0)
%23 = icmp eq i32* null, %22
br i1 %23, label %24, label %26
24: ; preds = %10
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %10
%27 = getelementptr inbounds [10240 x i8], [10240 x i8]* %2, i64 0, i64 0
%28 = call i32 @inet6_rth_segments(i8* %27)
store i32 %28, i32* %1
%29 = load i32, i32* %1
%30 = call i32 @checknum(i32 0, i32 %29, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%31 = getelementptr inbounds [10240 x i8], [10240 x i8]* %2, i64 0, i64 0
%32 = load i32, i32* @IPV6_RTHDR_TYPE_0
%33 = call i32* @inet6_rth_init(i8* %31, i32 10240, i32 %32, i32 127)
%34 = icmp eq i32* null, %33
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 (...) @abort()
unreachable
37: ; preds = %26
%38 = getelementptr inbounds [10240 x i8], [10240 x i8]* %2, i64 0, i64 0
%39 = call i32 @inet6_rth_segments(i8* %38)
store i32 %39, i32* %1
%40 = load i32, i32* %1
%41 = call i32 @checknum(i32 127, i32 %40, i32 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"test_rth_segments\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 = [14 x i8] c"127 segments\00\00"
define void @test_rth_segments() {
%1 = alloca [10240 x i8]
%2 = getelementptr inbounds [10240 x i8], [10240 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @set_funcname(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 19)
%4 = load i32, i32* @IPV6_RTHDR_TYPE_0
%5 = call i32* @inet6_rth_init(i8* %2, i32 10240, i32 %4, i32 0)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (...) @abort()
unreachable
9: ; preds = %0
%10 = load i32, i32* @IPV6_RTHDR_TYPE_0
%11 = xor i32 %10, -1
%12 = bitcast [10240 x i8]* %1 to i32*
store i32 %11, i32* %12
%13 = call i32 @inet6_rth_segments(i8* %2)
%14 = call i32 @checknum(i32 -1, i32 %13, i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @IPV6_RTHDR_TYPE_0
%16 = call i32* @inet6_rth_init(i8* %2, i32 10240, i32 %15, i32 0)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %9
%21 = call i32 @inet6_rth_segments(i8* %2)
%22 = call i32 @checknum(i32 0, i32 %21, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @IPV6_RTHDR_TYPE_0
%24 = call i32* @inet6_rth_init(i8* %2, i32 10240, i32 %23, i32 127)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 (...) @abort()
unreachable
28: ; preds = %20
%29 = call i32 @inet6_rth_segments(i8* %2)
%30 = call i32 @checknum(i32 127, i32 %29, i32 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
ret void
}