#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 ip6h_len;
};
typedef int socklen_t;

/* Variables and functions */
int inet6_opt_init(void *extbuf, socklen_t extlen) {
  if (extbuf != NULL) {
    if (extlen <= 0 || (extlen % 8) != 0 || extlen > 256 * 8)
      return -1;
    struct ip6_hbh *extp = (struct ip6_hbh *)extbuf;
    extp->ip6h_len = extlen / 8 - 1;
  }
  return sizeof(struct ip6_hbh);
}


x86 assembly (clang, -O0):
<inet6_opt_init>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116b <inet6_opt_init+0x6b>
cmpl   $0x0,-0x14(%rbp)
jle    1141 <inet6_opt_init+0x41>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1141 <inet6_opt_init+0x41>
cmpl   $0x800,-0x14(%rbp)
jle    114d <inet6_opt_init+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1172 <inet6_opt_init+0x72>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
sub    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_opt_init>:
mov    $0x4,%eax
test   %rdi,%rdi
je     112f <inet6_opt_init+0x2f>
mov    $0xffffffff,%eax
test   %esi,%esi
jle    112f <inet6_opt_init+0x2f>
cmp    $0x800,%esi
ja     112f <inet6_opt_init+0x2f>
mov    %esi,%ecx
and    $0x7,%ecx
jne    112f <inet6_opt_init+0x2f>
shr    $0x3,%esi
add    $0xffffffff,%esi
mov    %esi,(%rdi)
mov    $0x4,%eax
ret

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

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