#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 */
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
int64_t cgo_callback_conv_get_int(void *addr, int bits) {
  signed char bytes[8] = {0};
  int bcount = bits / 8;
  int i;
  for (i = 0; i < bcount; i++) {
    bytes[i] = *((char *)addr + i);
  }
  if (bytes[bcount - 1] < 0) {
    for (i = bcount; i < 8; i++) {
      bytes[i] = -1;
    }
  }
  return *(int64_t *)bytes;
}


x86 assembly (clang, -O0):
<cgo_callback_conv_get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1171 <cgo_callback_conv_get_int+0x61>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x14(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1144 <cgo_callback_conv_get_int+0x34>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x14(%rbp,%rax,1),%eax
cmp    $0x0,%eax
jge    11b3 <cgo_callback_conv_get_int+0xa3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11ae <cgo_callback_conv_get_int+0x9e>
movslq -0x1c(%rbp),%rax
movb   $0xff,-0x14(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <cgo_callback_conv_get_int+0x7d>
jmp    11b3 <cgo_callback_conv_get_int+0xa3>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgo_callback_conv_get_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
movq   $0x0,0x8(%rsp)
lea    0x7(%rbx),%eax
test   %esi,%esi
cmovns %esi,%eax
sar    $0x3,%eax
movslq %eax,%r14
lea    -0x1(%r14),%r15
cmp    $0x8,%esi
jl     115f <cgo_callback_conv_get_int+0x3f>
mov    %rdi,%rsi
mov    %r15d,%edx
add    $0x1,%rdx
lea    0x8(%rsp),%rdi
call   1040 <memcpy@plt>
cmpb   $0x0,0x8(%rsp,%r15,1)
jns    1192 <cgo_callback_conv_get_int+0x72>
cmp    $0x3f,%ebx
jg     1192 <cgo_callback_conv_get_int+0x72>
lea    (%rsp,%r14,1),%rdi
add    $0x8,%rdi
cmp    $0x8,%r14d
mov    $0x7,%edx
cmovge %r14d,%edx
sub    %r14d,%edx
add    $0x1,%rdx
mov    $0xff,%esi
call   1030 <memset@plt>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @cgo_callback_conv_get_int(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [8 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = bitcast [8 x i8]* %5 to i8*
%9 = load i32, i32* %4
%10 = sdiv i32 %9, 8
store i32 %10, i32* %6
store i32 0, i32* %7
br label %11
11: ; preds = %24, %2
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 %22
store i8 %20, i8* %23
br label %24
24: ; preds = %15
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %11
27: ; preds = %11
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %27
%36 = load i32, i32* %6
store i32 %36, i32* %7
br label %37
37: ; preds = %44, %35
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 8
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 %42
store i8 -1, i8* %43
br label %44
44: ; preds = %40
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %37
47: ; preds = %37
br label %48
48: ; preds = %47, %27
%49 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%50 = bitcast i8* %49 to i32*
%51 = load i32, i32* %50
ret i32 %51
}

LLVM IR (-O2):
define i32 @cgo_callback_conv_get_int(i8* nocapture %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = bitcast i64* %3 to [8 x i8]*
store i64 0, i64* %3
%6 = sdiv i32 %1, 8
%7 = icmp sgt i32 %1, 7
%8 = add nsw i32 %6, -1
br i1 %7, label %9, label %12
9: ; preds = %2
%10 = zext i32 %8 to i64
%11 = add nuw nsw i64 %10, 1
br label %12
12: ; preds = %2, %9
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp slt i8 %15, 0
%17 = icmp slt i32 %1, 64
%18 = and i1 %16, %17
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = sext i32 %6 to i64
%21 = getelementptr i8, i8* %4, i64 %20
%22 = call i32 @llvm.smax.i32(i32 %6, i32 7)
%23 = sub nsw i32 %22, %6
%24 = zext i32 %23 to i64
%25 = add nuw nsw i64 %24, 1
br label %26
26: ; preds = %19, %12
%27 = bitcast i64* %3 to i32*
%28 = load i32, i32* %27
ret i32 %28
}