#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 u_char;

/* Variables and functions */
int IP6OPT_PAD1;
int IP6OPT_PADN;
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
void inet6_insert_padopt(u_char *p, int len) {
  switch (len) {
  case 0:
    return;
  case 1:
    p[0] = IP6OPT_PAD1;
    return;
  default:
    p[0] = IP6OPT_PADN;
    p[1] = len - 2;
    memset(&p[2], 0, len - 2);
    return;
  }
}


x86 assembly (clang, -O0):
<inet6_insert_padopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     1143 <inet6_insert_padopt+0x33>
jmp    1132 <inet6_insert_padopt+0x22>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
je     1148 <inet6_insert_padopt+0x38>
jmp    115c <inet6_insert_padopt+0x4c>
jmp    118d <inet6_insert_padopt+0x7d>
mov    0x2e99(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    118d <inet6_insert_padopt+0x7d>
mov    0x2e75(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rdi
add    $0x8,%rdi
mov    -0xc(%rbp),%edx
sub    $0x2,%edx
xor    %esi,%esi
call   1030 <memset@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_insert_padopt>:
test   %esi,%esi
je     1126 <inet6_insert_padopt+0x16>
mov    %esi,%edx
cmp    $0x1,%esi
jne    1127 <inet6_insert_padopt+0x17>
mov    0x2ec6(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rdi)
ret
mov    0x2eaa(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rdi)
add    $0xfffffffe,%edx
mov    %edx,0x4(%rdi)
add    $0x8,%rdi
xor    %esi,%esi
jmp    1030 <memset@plt>

LLVM IR (-O0):
@IP6OPT_PAD1 = global i32 0
@IP6OPT_PADN = global i32 0
define void @inet6_insert_padopt(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
switch i32 %5, label %11 [
i32 0, label %6
i32 1, label %7
]
6: ; preds = %2
br label %24
7: ; preds = %2
%8 = load i32, i32* @IP6OPT_PAD1
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 0
store i32 %8, i32* %10
br label %24
11: ; preds = %2
%12 = load i32, i32* @IP6OPT_PADN
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i64 0
store i32 %12, i32* %14
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 2
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 1
store i32 %16, i32* %18
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 2
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 2
%23 = call i32 @memset(i32* %20, i32 0, i32 %22)
br label %24
24: ; preds = %11, %7, %6
ret void
}

LLVM IR (-O2):
@IP6OPT_PAD1 = global i32 0
@IP6OPT_PADN = global i32 0
define void @inet6_insert_padopt(i32* %0, i32 %1) {
switch i32 %1, label %5 [
i32 0, label %11
i32 1, label %3
]
3: ; preds = %2
%4 = load i32, i32* @IP6OPT_PAD1
store i32 %4, i32* %0
br label %11
5: ; preds = %2
%6 = load i32, i32* @IP6OPT_PADN
store i32 %6, i32* %0
%7 = add nsw i32 %1, -2
%8 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %7, i32* %8
%9 = getelementptr inbounds i32, i32* %0, i64 2
%10 = tail call i32 @memset(i32* %9, i32 0, i32 %7)
br label %11
11: ; preds = %2, %5, %3
ret void
}