#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 */
int inet6_opt_init(void *extbuf, socklen_t extlen) {
  struct ip6_ext *ext = (struct ip6_ext *)extbuf;
  if (ext) {
    if (extlen <= 0 || (extlen % 8))
      return (-1);
    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)
cmpq   $0x0,-0x20(%rbp)
je     1157 <inet6_opt_init+0x57>
cmpl   $0x0,-0x14(%rbp)
jle    113c <inet6_opt_init+0x3c>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1148 <inet6_opt_init+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    115e <inet6_opt_init+0x5e>
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    $0x2,%eax
test   %rdi,%rdi
je     1127 <inet6_opt_init+0x27>
mov    $0xffffffff,%eax
test   %esi,%esi
jle    1127 <inet6_opt_init+0x27>
mov    %esi,%ecx
and    $0x7,%ecx
jne    1127 <inet6_opt_init+0x27>
shr    $0x3,%esi
add    $0xffffffff,%esi
mov    %esi,(%rdi)
mov    $0x2,%eax
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 %struct.ip6_ext*, %struct.ip6_ext** %6
%10 = icmp ne %struct.ip6_ext* %9, null
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = load i32, i32* %5
%16 = srem i32 %15, 8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14, %11
store i32 -1, i32* %3
br label %26
19: ; preds = %14
%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, %2
store i32 2, i32* %3
br label %26
26: ; preds = %25, %18
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @inet6_opt_init(i8* writeonly %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = icmp sgt i32 %1, 0
%6 = and i32 %1, 7
%7 = icmp eq i32 %6, 0
%8 = and i1 %5, %7
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = lshr 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 = %2, %9, %4
%14 = phi i32 [ -1, %4 ], [ 2, %9 ], [ 2, %2 ]
ret i32 %14
}