#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 */

/* Variables and functions */
int /*<<< orphan*/ GO_free(unsigned int *);
unsigned int *GO_malloc(int);
unsigned int calc_stopbits(unsigned int *);
unsigned char *get_subbuf(unsigned char const *, int *, int *, int *);
const int calcdis_s(const unsigned char *subbuf, const int i) {
  unsigned int *distbl = GO_malloc(32 * 4), dis_s;
  int j, l, d, t, len, maxlen;
  for (j = 0; j < 32; j++)
    distbl[j] = 0;
  for (;;) {
    subbuf = get_subbuf(subbuf, &t, &d, &l);
    if (t == 0x00)
      break;
    if (t == 0x01)
      continue;
    if (l < i + 1)
      continue;
    if (d == -1)
      j = 0;
    else {
      j = 31;
      while (d & 0x80000000) {
        d <<= 1;
        j--;
      }
    }
    distbl[j]++;
  }
  dis_s = calc_stopbits(distbl);
  GO_free(distbl);
  return dis_s;
}


x86 assembly (clang, -O0):
<calcdis_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x80,%edi
call   1050 <GO_malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x20,-0x20(%rbp)
jge    118b <calcdis_s+0x4b>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1164 <calcdis_s+0x24>
jmp    1190 <calcdis_s+0x50>
mov    -0x8(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1060 <get_subbuf@plt>
mov    %rax,-0x8(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11b8 <calcdis_s+0x78>
jmp    123d <calcdis_s+0xfd>
cmpl   $0x1,-0x2c(%rbp)
jne    11c7 <calcdis_s+0x87>
jmp    1190 <calcdis_s+0x50>
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11dd <calcdis_s+0x9d>
jmp    1190 <calcdis_s+0x50>
cmpl   $0xffffffff,-0x28(%rbp)
jne    11f3 <calcdis_s+0xb3>
movl   $0x0,-0x20(%rbp)
jmp    1227 <calcdis_s+0xe7>
movl   $0x1f,-0x20(%rbp)
mov    -0x28(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1222 <calcdis_s+0xe2>
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11fa <calcdis_s+0xba>
jmp    1227 <calcdis_s+0xe7>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    1190 <calcdis_s+0x50>
mov    -0x18(%rbp),%rdi
call   1030 <calc_stopbits@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <GO_free@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcdis_s>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%rbx
mov    $0x80,%edi
call   1050 <GO_malloc@plt>
mov    %rax,%r14
xorps  %xmm0,%xmm0
movups %xmm0,0x70(%rax)
movups %xmm0,0x60(%rax)
movups %xmm0,0x50(%rax)
movups %xmm0,0x40(%rax)
movups %xmm0,0x30(%rax)
movups %xmm0,0x20(%rax)
movups %xmm0,0x10(%rax)
movups %xmm0,(%rax)
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0x14(%rsp),%rbp
jmp    119d <calcdis_s+0x5d>
xor    %eax,%eax
cltq
addl   $0x1,(%r14,%rax,4)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1060 <get_subbuf@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%eax
cmp    $0x1,%eax
je     119d <calcdis_s+0x5d>
test   %eax,%eax
je     11ef <calcdis_s+0xaf>
cmp    %r15d,0x14(%rsp)
jle    119d <calcdis_s+0x5d>
mov    0xc(%rsp),%ecx
cmp    $0xffffffff,%ecx
je     1194 <calcdis_s+0x54>
mov    $0x1f,%eax
test   %ecx,%ecx
jns    1196 <calcdis_s+0x56>
mov    $0x1f,%eax
nopl   0x0(%rax)
add    %ecx,%ecx
add    $0xffffffff,%eax
test   %ecx,%ecx
js     11e0 <calcdis_s+0xa0>
mov    %ecx,0xc(%rsp)
jmp    1196 <calcdis_s+0x56>
mov    %r14,%rdi
call   1030 <calc_stopbits@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <GO_free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calcdis_s(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%13 = call i32* @GO_malloc(i32 128)
store i32* %13, i32** %5
store i32 0, i32* %7
br label %14
14: ; preds = %22, %2
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 32
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i32*, i32** %5
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
store i32 0, i32* %21
br label %22
22: ; preds = %17
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %14
25: ; preds = %14
br label %26
26: ; preds = %57, %41, %35, %25
%27 = load i8*, i8** %3
%28 = call i8* @get_subbuf(i8* %27, i32* %10, i32* %9, i32* %8)
store i8* %28, i8** %3
%29 = load i32, i32* %10
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %64
32: ; preds = %26
%33 = load i32, i32* %10
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %32
br label %26
36: ; preds = %32
%37 = load i32, i32* %8
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
%40 = icmp slt i32 %37, %39
br i1 %40, label %41, label %42
41: ; preds = %36
br label %26
42: ; preds = %36
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 0, i32* %7
br label %57
46: ; preds = %42
store i32 31, i32* %7
br label %47
47: ; preds = %51, %46
%48 = load i32, i32* %9
%49 = and i32 %48, -2147483648
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = load i32, i32* %9
%53 = shl i32 %52, 1
store i32 %53, i32* %9
%54 = load i32, i32* %7
%55 = add nsw i32 %54, -1
store i32 %55, i32* %7
br label %47
56: ; preds = %47
br label %57
57: ; preds = %56, %45
%58 = load i32*, i32** %5
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
%62 = load i32, i32* %61
%63 = add i32 %62, 1
store i32 %63, i32* %61
br label %26
64: ; preds = %31
%65 = load i32*, i32** %5
%66 = call i32 @calc_stopbits(i32* %65)
store i32 %66, i32* %6
%67 = load i32*, i32** %5
%68 = call i32 @GO_free(i32* %67)
%69 = load i32, i32* %6
ret i32 %69
}

LLVM IR (-O2):
define i32 @calcdis_s(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32* @GO_malloc(i32 128)
%7 = bitcast i32* %6 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
br label %11
11: ; preds = %36, %2
%12 = phi i8* [ %0, %2 ], [ %13, %36 ]
%13 = call i8* @get_subbuf(i8* %12, i32* %5, i32* %4, i32* %3)
%14 = load i32, i32* %5
switch i32 %14, label %15 [
i32 0, label %37
i32 1, label %36
]
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, %1
br i1 %17, label %18, label %36
18: ; preds = %15
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, -1
br i1 %20, label %30, label %21
21: ; preds = %18
%22 = icmp sgt i32 %19, -1
br i1 %22, label %30, label %23
23: ; preds = %21, %23
%24 = phi i32 [ %27, %23 ], [ 31, %21 ]
%25 = phi i32 [ %26, %23 ], [ %19, %21 ]
%26 = shl i32 %25, 1
%27 = add nsw i32 %24, -1
%28 = icmp sgt i32 %26, -1
br i1 %28, label %29, label %23
29: ; preds = %23
store i32 %26, i32* %4
br label %30
30: ; preds = %21, %29, %18
%31 = phi i32 [ 0, %18 ], [ %27, %29 ], [ 31, %21 ]
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %6, i64 %32
%34 = load i32, i32* %33
%35 = add i32 %34, 1
store i32 %35, i32* %33
br label %36
36: ; preds = %30, %15, %11
br label %11
37: ; preds = %11
%38 = call i32 @calc_stopbits(i32* %6)
%39 = call i32 @GO_free(i32* %6)
ret i32 %38
}