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

/* Variables and functions */
int /*<<< orphan*/ add_padding(void *, int, int);
int inet6_opt_finish(void *extbuf, socklen_t extlen, int offset) {
  if (offset < sizeof(struct ip6_hbh))
    return -1;
  int npad = (8 - (offset & 7)) & 7;
  if (extbuf != NULL) {
    if (offset + npad > extlen)
      return -1;
    add_padding(extbuf, offset, npad);
  }
  return offset + npad;
}


x86 assembly (clang, -O0):
<inet6_opt_finish>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x4,%rax
jae    113c <inet6_opt_finish+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <inet6_opt_finish+0x7d>
mov    -0x18(%rbp),%ecx
and    $0x7,%ecx
mov    $0x8,%eax
sub    %ecx,%eax
and    $0x7,%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1184 <inet6_opt_finish+0x74>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1175 <inet6_opt_finish+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <inet6_opt_finish+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <add_padding@plt>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_opt_finish>:
push   %rbx
mov    $0xffffffff,%eax
cmp    $0x4,%edx
jb     1139 <inet6_opt_finish+0x29>
mov    %edx,%ecx
neg    %ecx
and    $0x7,%ecx
lea    (%rcx,%rdx,1),%ebx
test   %rdi,%rdi
je     1137 <inet6_opt_finish+0x27>
cmp    %esi,%ebx
jg     1139 <inet6_opt_finish+0x29>
mov    %edx,%esi
mov    %ecx,%edx
call   1030 <add_padding@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @inet6_opt_finish(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = sext i32 %9 to i64
%11 = icmp ult i64 %10, 4
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %36
13: ; preds = %3
%14 = load i32, i32* %7
%15 = and i32 %14, 7
%16 = sub nsw i32 8, %15
%17 = and i32 %16, 7
store i32 %17, i32* %8
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %32
20: ; preds = %13
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = add nsw i32 %21, %22
%24 = load i32, i32* %6
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 -1, i32* %4
br label %36
27: ; preds = %20
%28 = load i8*, i8** %5
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = call i32 @add_padding(i8* %28, i32 %29, i32 %30)
br label %32
32: ; preds = %27, %13
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = add nsw i32 %33, %34
store i32 %35, i32* %4
br label %36
36: ; preds = %32, %26, %12
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @inet6_opt_finish(i8* %0, i32 %1, i32 %2) {
%4 = icmp ult i32 %2, 4
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = sub i32 0, %2
%7 = and i32 %6, 7
%8 = icmp eq i8* %0, null
%9 = add nsw i32 %7, %2
br i1 %8, label %14, label %10
10: ; preds = %5
%11 = icmp sgt i32 %9, %1
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i32 @add_padding(i8* %0, i32 %2, i32 %7)
br label %14
14: ; preds = %5, %12, %10, %3
%15 = phi i32 [ -1, %3 ], [ -1, %10 ], [ %9, %12 ], [ %9, %5 ]
ret i32 %15
}