#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*/ *caddr_t;

/* Variables and functions */
int /*<<< orphan*/ IPV6_RTHDR_TYPE_0;
int /*<<< orphan*/ checkptr(int /*<<< orphan*/ *, char *, char *);
char *inet6_rth_init(void *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ set_funcname(char *, int);
void test_rth_init() {
  char buf[10240];
  char *pbuf;
  set_funcname("test_rth_init", sizeof("test_rth_init\0"));
  pbuf = inet6_rth_init((void *)buf, 10, IPV6_RTHDR_TYPE_0, 100);
  checkptr(NULL, pbuf, "buffer too small\0");
  pbuf = inet6_rth_init((void *)buf, 10240, IPV6_RTHDR_TYPE_0, 0);
  checkptr((caddr_t)&buf, pbuf, "0 segments\0");
  pbuf = inet6_rth_init((void *)buf, 10240, IPV6_RTHDR_TYPE_0, 127);
  checkptr((caddr_t)&buf, pbuf, "127 segments\0");
  pbuf = inet6_rth_init((void *)buf, 10240, IPV6_RTHDR_TYPE_0, -1);
  checkptr(NULL, pbuf, "negative number of segments\0");
  pbuf = inet6_rth_init((void *)buf, 10240, IPV6_RTHDR_TYPE_0, 128);
  checkptr(NULL, pbuf, "128 segments\0");
}


x86 assembly (clang, -O0):
<test_rth_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2810,%rsp
lea    0xebe(%rip),%rdi
mov    $0xf,%esi
call   1050 <set_funcname@plt>
lea    -0x2800(%rbp),%rdi
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
mov    $0x64,%ecx
call   1040 <inet6_rth_init@plt>
mov    %rax,-0x2808(%rbp)
mov    -0x2808(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xe8a(%rip),%rdx
call   1030 <checkptr@plt>
lea    -0x2800(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
mov    $0x2800,%esi
xor    %ecx,%ecx
call   1040 <inet6_rth_init@plt>
mov    %rax,-0x2808(%rbp)
lea    -0x2800(%rbp),%rdi
mov    -0x2808(%rbp),%rsi
lea    0xe5f(%rip),%rdx
call   1030 <checkptr@plt>
lea    -0x2800(%rbp),%rdi
mov    0x2e14(%rip),%rax
mov    (%rax),%edx
mov    $0x2800,%esi
mov    $0x7f,%ecx
call   1040 <inet6_rth_init@plt>
mov    %rax,-0x2808(%rbp)
lea    -0x2800(%rbp),%rdi
mov    -0x2808(%rbp),%rsi
lea    0xe2b(%rip),%rdx
call   1030 <checkptr@plt>
lea    -0x2800(%rbp),%rdi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
mov    $0x2800,%esi
mov    $0xffffffff,%ecx
call   1040 <inet6_rth_init@plt>
mov    %rax,-0x2808(%rbp)
mov    -0x2808(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xdfc(%rip),%rdx
call   1030 <checkptr@plt>
lea    -0x2800(%rbp),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%edx
mov    $0x2800,%esi
mov    $0x80,%ecx
call   1040 <inet6_rth_init@plt>
mov    %rax,-0x2808(%rbp)
mov    -0x2808(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xddc(%rip),%rdx
call   1030 <checkptr@plt>
add    $0x2810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rth_init>:
push   %r14
push   %rbx
sub    $0x2808,%rsp
lea    0xebf(%rip),%rdi
mov    $0xf,%esi
call   1050 <set_funcname@plt>
mov    0x2e96(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x64,%ecx
call   1040 <inet6_rth_init@plt>
lea    0xe9d(%rip),%rdx
xor    %edi,%edi
mov    %rax,%rsi
call   1030 <checkptr@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x2800,%esi
xor    %ecx,%ecx
call   1040 <inet6_rth_init@plt>
lea    0xe8c(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <checkptr@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x2800,%esi
mov    $0x7f,%ecx
call   1040 <inet6_rth_init@plt>
lea    0xe71(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <checkptr@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x2800,%esi
mov    $0xffffffff,%ecx
call   1040 <inet6_rth_init@plt>
lea    0xe58(%rip),%rdx
xor    %edi,%edi
mov    %rax,%rsi
call   1030 <checkptr@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x2800,%esi
mov    $0x80,%ecx
call   1040 <inet6_rth_init@plt>
lea    0xe4f(%rip),%rdx
xor    %edi,%edi
mov    %rax,%rsi
call   1030 <checkptr@plt>
add    $0x2808,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"test_rth_init\00"
@IPV6_RTHDR_TYPE_0 = global i32 0
@.str.1 = [18 x i8] c"buffer too small\00\00"
@.str.2 = [12 x i8] c"0 segments\00\00"
@.str.3 = [14 x i8] c"127 segments\00\00"
@.str.4 = [29 x i8] c"negative number of segments\00\00"
@.str.5 = [14 x i8] c"128 segments\00\00"
define void @test_rth_init() {
%1 = alloca [10240 x i8]
%2 = alloca i8*
%3 = call i32 @set_funcname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 15)
%4 = getelementptr inbounds [10240 x i8], [10240 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @IPV6_RTHDR_TYPE_0
%6 = call i8* @inet6_rth_init(i8* %4, i32 10, i32 %5, i32 100)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @checkptr(i32* null, i8* %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [10240 x i8], [10240 x i8]* %1, i64 0, i64 0
%10 = load i32, i32* @IPV6_RTHDR_TYPE_0
%11 = call i8* @inet6_rth_init(i8* %9, i32 10240, i32 %10, i32 0)
store i8* %11, i8** %2
%12 = bitcast [10240 x i8]* %1 to i32*
%13 = load i8*, i8** %2
%14 = call i32 @checkptr(i32* %12, i8* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [10240 x i8], [10240 x i8]* %1, i64 0, i64 0
%16 = load i32, i32* @IPV6_RTHDR_TYPE_0
%17 = call i8* @inet6_rth_init(i8* %15, i32 10240, i32 %16, i32 127)
store i8* %17, i8** %2
%18 = bitcast [10240 x i8]* %1 to i32*
%19 = load i8*, i8** %2
%20 = call i32 @checkptr(i32* %18, i8* %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%21 = getelementptr inbounds [10240 x i8], [10240 x i8]* %1, i64 0, i64 0
%22 = load i32, i32* @IPV6_RTHDR_TYPE_0
%23 = call i8* @inet6_rth_init(i8* %21, i32 10240, i32 %22, i32 -1)
store i8* %23, i8** %2
%24 = load i8*, i8** %2
%25 = call i32 @checkptr(i32* null, i8* %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%26 = getelementptr inbounds [10240 x i8], [10240 x i8]* %1, i64 0, i64 0
%27 = load i32, i32* @IPV6_RTHDR_TYPE_0
%28 = call i8* @inet6_rth_init(i8* %26, i32 10240, i32 %27, i32 128)
store i8* %28, i8** %2
%29 = load i8*, i8** %2
%30 = call i32 @checkptr(i32* null, i8* %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"test_rth_init\00"
@IPV6_RTHDR_TYPE_0 = global i32 0
@.str.1 = [18 x i8] c"buffer too small\00\00"
@.str.2 = [12 x i8] c"0 segments\00\00"
@.str.3 = [14 x i8] c"127 segments\00\00"
@.str.4 = [29 x i8] c"negative number of segments\00\00"
@.str.5 = [14 x i8] c"128 segments\00\00"
define void @test_rth_init() {
%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 ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 15)
%4 = load i32, i32* @IPV6_RTHDR_TYPE_0
%5 = call i8* @inet6_rth_init(i8* %2, i32 10, i32 %4, i32 100)
%6 = call i32 @checkptr(i32* null, i8* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @IPV6_RTHDR_TYPE_0
%8 = call i8* @inet6_rth_init(i8* %2, i32 10240, i32 %7, i32 0)
%9 = bitcast [10240 x i8]* %1 to i32*
%10 = call i32 @checkptr(i32* %9, i8* %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @IPV6_RTHDR_TYPE_0
%12 = call i8* @inet6_rth_init(i8* %2, i32 10240, i32 %11, i32 127)
%13 = call i32 @checkptr(i32* %9, i8* %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @IPV6_RTHDR_TYPE_0
%15 = call i8* @inet6_rth_init(i8* %2, i32 10240, i32 %14, i32 -1)
%16 = call i32 @checkptr(i32* null, i8* %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%17 = load i32, i32* @IPV6_RTHDR_TYPE_0
%18 = call i8* @inet6_rth_init(i8* %2, i32 10240, i32 %17, i32 128)
%19 = call i32 @checkptr(i32* null, i8* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
ret void
}