#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_ext {
  int ip6e_len;
};
typedef int socklen_t;

/* Variables and functions */
__attribute__((visibility("default"))) int inet6_opt_init(void *extbuf,
                                                          socklen_t extlen) {
  struct ip6_ext *ext = (struct ip6_ext *)extbuf;
  if (extlen == 0 || (extlen % 8)) {
    return (-1);
  }
  if (ext) {
    ext->ip6e_len = (extlen >> 3) - 1;
  }
  return (2);
}


x86 assembly (clang, -O0):
<inet6_opt_init>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1131 <inet6_opt_init+0x31>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     113d <inet6_opt_init+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    115e <inet6_opt_init+0x5e>
cmpq   $0x0,-0x20(%rbp)
je     1157 <inet6_opt_init+0x57>
mov    -0x14(%rbp),%ecx
sar    $0x3,%ecx
sub    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_opt_init>:
mov    $0xffffffff,%eax
test   %esi,%esi
je     1122 <inet6_opt_init+0x22>
mov    %esi,%ecx
and    $0x7,%ecx
jne    1122 <inet6_opt_init+0x22>
mov    $0x2,%eax
test   %rdi,%rdi
je     1122 <inet6_opt_init+0x22>
sar    $0x3,%esi
add    $0xffffffff,%esi
mov    %esi,(%rdi)
ret

LLVM IR (-O0):
%struct.ip6_ext = type { i32 }
define i32 @inet6_opt_init(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.ip6_ext*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = bitcast i8* %7 to %struct.ip6_ext*
store %struct.ip6_ext* %8, %struct.ip6_ext** %6
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* %5
%13 = srem i32 %12, 8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11, %2
store i32 -1, i32* %3
br label %26
16: ; preds = %11
%17 = load %struct.ip6_ext*, %struct.ip6_ext** %6
%18 = icmp ne %struct.ip6_ext* %17, null
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* %5
%21 = ashr i32 %20, 3
%22 = sub nsw i32 %21, 1
%23 = load %struct.ip6_ext*, %struct.ip6_ext** %6
%24 = getelementptr inbounds %struct.ip6_ext, %struct.ip6_ext* %23, i32 0, i32 0
store i32 %22, i32* %24
br label %25
25: ; preds = %19, %16
store i32 2, i32* %3
br label %26
26: ; preds = %25, %15
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @inet6_opt_init(i8* writeonly %0, i32 %1) {
%3 = icmp ne i32 %1, 0
%4 = and i32 %1, 7
%5 = icmp eq i32 %4, 0
%6 = and i1 %3, %5
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = icmp eq i8* %0, null
br i1 %8, label %13, label %9
9: ; preds = %7
%10 = ashr i32 %1, 3
%11 = add nsw i32 %10, -1
%12 = bitcast i8* %0 to i32*
store i32 %11, i32* %12
br label %13
13: ; preds = %7, %9, %2
%14 = phi i32 [ -1, %2 ], [ 2, %9 ], [ 2, %7 ]
ret i32 %14
}