#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 coder {
  int dummy;
};

/* Variables and functions */
unsigned char *Ptngc_pack_array(struct coder *, int *, int *, int, int,
                                int const, int /*<<< orphan*/);
int /*<<< orphan*/ free(unsigned char *);
int determine_best_coding_stop_bits(struct coder *coder, int *input,
                                    int *length, int *coding_parameter,
                                    const int natoms) {
  int bits;
  unsigned char *packed;
  int best_length = 0;
  int new_parameter = -1;
  int io_length;
  for (bits = 1; bits < 20; bits++) {
    io_length = *length;
    packed = Ptngc_pack_array(coder, input, &io_length, 1, bits, natoms, 0);
    if (packed) {
      if ((new_parameter == -1) || (io_length < best_length)) {
        new_parameter = bits;
        best_length = io_length;
      }
      free(packed);
    }
  }
  if (new_parameter == -1)
    return 1;
  *coding_parameter = new_parameter;
  *length = best_length;
  return 0;
}


x86 assembly (clang, -O0):
<determine_best_coding_stop_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0xffffffff,-0x40(%rbp)
movl   $0x1,-0x30(%rbp)
cmpl   $0x14,-0x30(%rbp)
jge    11d8 <determine_best_coding_stop_bits+0xb8>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
lea    -0x44(%rbp),%rdx
mov    $0x1,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
call   1040 <Ptngc_pack_array@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11c5 <determine_best_coding_stop_bits+0xa5>
cmpl   $0xffffffff,-0x40(%rbp)
je     11b0 <determine_best_coding_stop_bits+0x90>
mov    -0x44(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    11bc <determine_best_coding_stop_bits+0x9c>
mov    -0x30(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    11ca <determine_best_coding_stop_bits+0xaa>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1151 <determine_best_coding_stop_bits+0x31>
cmpl   $0xffffffff,-0x40(%rbp)
jne    11ee <determine_best_coding_stop_bits+0xce>
movl   $0x1,-0x4(%rbp)
jmp    1207 <determine_best_coding_stop_bits+0xe7>
mov    -0x40(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<determine_best_coding_stop_bits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,0xc(%rsp)
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,%rbp
mov    $0x1,%ebx
xor    %r12d,%r12d
mov    $0xffffffff,%r13d
jmp    1176 <determine_best_coding_stop_bits+0x56>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rdi
call   1030 <free@plt>
mov    %r14d,%r12d
mov    %r15d,%r13d
add    $0x1,%ebx
cmp    $0x14,%ebx
je     11cd <determine_best_coding_stop_bits+0xad>
mov    0x10(%rsp),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %rbp,%rdi
mov    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    $0x1,%ecx
mov    %ebx,%r8d
mov    0xc(%rsp),%r9d
call   1040 <Ptngc_pack_array@plt>
test   %rax,%rax
je     116e <determine_best_coding_stop_bits+0x4e>
cmp    $0xffffffff,%r13d
sete   %cl
mov    0x8(%rsp),%r14d
cmp    %r12d,%r14d
setl   %dl
or     %cl,%dl
mov    %ebx,%r15d
jne    1160 <determine_best_coding_stop_bits+0x40>
mov    %r12d,%r14d
mov    %r13d,%r15d
jmp    1160 <determine_best_coding_stop_bits+0x40>
cmp    $0xffffffff,%r13d
je     11e7 <determine_best_coding_stop_bits+0xc7>
mov    0x18(%rsp),%rax
mov    %r13d,(%rax)
mov    0x10(%rsp),%rax
mov    %r12d,(%rax)
xor    %eax,%eax
jmp    11ec <determine_best_coding_stop_bits+0xcc>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.coder = type { i32 }
define i32 @determine_best_coding_stop_bits(%struct.coder* %0, i32* %1, i32* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.coder*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store %struct.coder* %0, %struct.coder** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
store i32 0, i32* %14
store i32 -1, i32* %15
store i32 1, i32* %12
br label %17
17: ; preds = %44, %5
%18 = load i32, i32* %12
%19 = icmp slt i32 %18, 20
br i1 %19, label %20, label %47
20: ; preds = %17
%21 = load i32*, i32** %9
%22 = load i32, i32* %21
store i32 %22, i32* %16
%23 = load %struct.coder*, %struct.coder** %7
%24 = load i32*, i32** %8
%25 = load i32, i32* %12
%26 = load i32, i32* %11
%27 = call i8* @Ptngc_pack_array(%struct.coder* %23, i32* %24, i32* %16, i32 1, i32 %25, i32 %26, i32 0)
store i8* %27, i8** %13
%28 = load i8*, i8** %13
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %43
30: ; preds = %20
%31 = load i32, i32* %15
%32 = icmp eq i32 %31, -1
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = load i32, i32* %16
%35 = load i32, i32* %14
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %33, %30
%38 = load i32, i32* %12
store i32 %38, i32* %15
%39 = load i32, i32* %16
store i32 %39, i32* %14
br label %40
40: ; preds = %37, %33
%41 = load i8*, i8** %13
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %40, %20
br label %44
44: ; preds = %43
%45 = load i32, i32* %12
%46 = add nsw i32 %45, 1
store i32 %46, i32* %12
br label %17
47: ; preds = %17
%48 = load i32, i32* %15
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 1, i32* %6
br label %56
51: ; preds = %47
%52 = load i32, i32* %15
%53 = load i32*, i32** %10
store i32 %52, i32* %53
%54 = load i32, i32* %14
%55 = load i32*, i32** %9
store i32 %54, i32* %55
store i32 0, i32* %6
br label %56
56: ; preds = %51, %50
%57 = load i32, i32* %6
ret i32 %57
}

LLVM IR (-O2):
%struct.coder = type { i32 }
define i32 @determine_best_coding_stop_bits(%struct.coder* %0, i32* %1, i32* nocapture %2, i32* nocapture writeonly %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
br label %8
8: ; preds = %5, %23
%9 = phi i32 [ -1, %5 ], [ %25, %23 ]
%10 = phi i32 [ 0, %5 ], [ %24, %23 ]
%11 = phi i32 [ 1, %5 ], [ %26, %23 ]
%12 = load i32, i32* %2
store i32 %12, i32* %6
%13 = call i8* @Ptngc_pack_array(%struct.coder* %0, i32* %1, i32* %6, i32 1, i32 %11, i32 %4, i32 0)
%14 = icmp eq i8* %13, null
br i1 %14, label %23, label %15
15: ; preds = %8
%16 = icmp eq i32 %9, -1
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, %10
%19 = select i1 %16, i1 true, i1 %18
%20 = select i1 %19, i32 %17, i32 %10
%21 = select i1 %19, i32 %11, i32 %9
%22 = call i32 @free(i8* %13)
br label %23
23: ; preds = %8, %15
%24 = phi i32 [ %20, %15 ], [ %10, %8 ]
%25 = phi i32 [ %21, %15 ], [ %9, %8 ]
%26 = add nuw nsw i32 %11, 1
%27 = icmp eq i32 %26, 20
br i1 %27, label %28, label %8
28: ; preds = %23
%29 = icmp eq i32 %25, -1
br i1 %29, label %31, label %30
30: ; preds = %28
store i32 %25, i32* %3
store i32 %24, i32* %2
br label %31
31: ; preds = %28, %30
%32 = phi i32 [ 0, %30 ], [ 1, %28 ]
ret i32 %32
}