#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 nsc_enc_bit(int *, int, int, int *, int, int);
void nsc_transit(int output_p[], int trans_p[], int input, int g[], int KK,
                 int nn) {
  int nextstate[1];
  int state, states;
  states = (1 << (KK - 1));
  for (state = 0; state < states; state++) {
    output_p[state] = nsc_enc_bit(nextstate, input, state, g, KK, nn);
    trans_p[state] = nextstate[0];
  }
  return;
}


x86 assembly (clang, -O0):
<nsc_transit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1196 <nsc_transit+0x86>
lea    -0x2c(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
call   1030 <nsc_enc_bit@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1146 <nsc_transit+0x36>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nsc_transit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
lea    -0x1(%r8),%ecx
cmp    $0x1f,%ecx
je     1198 <nsc_transit+0x88>
mov    %r9d,%r12d
mov    %edx,%r13d
mov    %rsi,%r15
mov    $0x1,%eax
mov    $0x1,%ebp
shl    %cl,%ebp
cmp    $0x2,%ebp
cmovl  %eax,%ebp
mov    %rbp,0x8(%rsp)
xor    %r14d,%r14d
mov    %rdi,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x4(%rsp),%rdi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
mov    %r8,%rbp
mov    %r12d,%r9d
call   1030 <nsc_enc_bit@plt>
mov    0x10(%rsp),%rdi
mov    %rbp,%r8
mov    %eax,(%rdi,%r14,4)
mov    0x4(%rsp),%eax
mov    %eax,(%r15,%r14,4)
add    $0x1,%r14
cmp    %r14,0x8(%rsp)
jne    1160 <nsc_transit+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @nsc_transit(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i32 %2, i32* %3, i32 %4, i32 %5) {
%7 = alloca [1 x i32]
%8 = bitcast [1 x i32]* %7 to i8*
%9 = add nsw i32 %4, -1
%10 = icmp eq i32 %9, 31
br i1 %10, label %25, label %11
11: ; preds = %6
%12 = shl nuw i32 1, %9
%13 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
%14 = call i32 @llvm.smax.i32(i32 %12, i32 1)
%15 = zext i32 %14 to i64
br label %16
16: ; preds = %11, %16
%17 = phi i64 [ 0, %11 ], [ %23, %16 ]
%18 = trunc i64 %17 to i32
%19 = call i32 @nsc_enc_bit(i32* %13, i32 %2, i32 %18, i32* %3, i32 %4, i32 %5)
%20 = getelementptr inbounds i32, i32* %0, i64 %17
store i32 %19, i32* %20
%21 = load i32, i32* %13
%22 = getelementptr inbounds i32, i32* %1, i64 %17
store i32 %21, i32* %22
%23 = add nuw nsw i64 %17, 1
%24 = icmp eq i64 %23, %15
br i1 %24, label %25, label %16
25: ; preds = %16, %6
ret void
}