#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 (extlen < 0 || (extlen % 8))
    return (-1);
  if (ext) {
    if (extlen == 0)
      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)
cmpl   $0x0,-0x14(%rbp)
jl     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    1174 <inet6_opt_init+0x74>
cmpq   $0x0,-0x20(%rbp)
je     116d <inet6_opt_init+0x6d>
cmpl   $0x0,-0x14(%rbp)
jne    115e <inet6_opt_init+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1174 <inet6_opt_init+0x74>
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   $0x80000007,%esi
je     110e <inet6_opt_init+0xe>
ret
test   %rdi,%rdi
je     111f <inet6_opt_init+0x1f>
test   %esi,%esi
je     110d <inet6_opt_init+0xd>
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 i32, i32* %5
%10 = icmp slt 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 %30
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 %29
19: ; preds = %16
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 -1, i32* %3
br label %30
23: ; preds = %19
%24 = load i32, i32* %5
%25 = ashr i32 %24, 3
%26 = sub nsw i32 %25, 1
%27 = load %struct.ip6_ext*, %struct.ip6_ext** %6
%28 = getelementptr inbounds %struct.ip6_ext, %struct.ip6_ext* %27, i32 0, i32 0
store i32 %26, i32* %28
br label %29
29: ; preds = %23, %16
store i32 2, i32* %3
br label %30
30: ; preds = %29, %22, %15
%31 = load i32, i32* %3
ret i32 %31
}

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