#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 _ada_use_c2phc(int, int *, int *, double *);
int localization_poset(int m, int p, int q, int *nc, char *ps) {
  int i, fail;
  int mpq[3];
  int buffer_size = 10240;
  int b[buffer_size];
  double *c;
  mpq[0] = m;
  mpq[1] = p;
  mpq[2] = q;
  fail = _ada_use_c2phc(224, mpq, b, c);
  *nc = mpq[0];
  for (i = 0; i < *nc; i++)
    ps[i] = (char)b[i];
  ps[*nc] = '\0';
  return fail;
}


x86 assembly (clang, -O0):
<localization_poset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x2800,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x34(%rbp),%rsi
mov    -0x50(%rbp),%rcx
mov    $0xe0,%edi
call   1030 <_ada_use_c2phc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    11c3 <localization_poset+0xb3>
mov    -0x58(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118e <localization_poset+0x7e>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
mov    -0x40(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<localization_poset>:
push   %r15
push   %r14
push   %rbx
sub    $0xa010,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rsp,%r15
mov    %edi,0x4(%rsp)
mov    %esi,0x8(%rsp)
mov    %edx,0xc(%rsp)
lea    0x4(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    $0xe0,%edi
call   1030 <_ada_use_c2phc@plt>
mov    0x4(%rsp),%ecx
mov    %ecx,(%rbx)
test   %ecx,%ecx
jle    1175 <localization_poset+0x65>
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x10(%rsp,%rdx,4),%ecx
mov    %cl,(%r14,%rdx,1)
add    $0x1,%rdx
movslq (%rbx),%rcx
cmp    %rcx,%rdx
jl     1160 <localization_poset+0x50>
movslq %ecx,%rcx
movb   $0x0,(%r14,%rcx,1)
mov    %r15,%rsp
add    $0xa010,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @localization_poset(i32 %0, i32 %1, i32 %2, i32* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca [3 x i32]
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i64
%17 = alloca double*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i8* %4, i8** %10
store i32 10240, i32* %14
%18 = load i32, i32* %14
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %15
%21 = alloca i32, i64 %19
store i64 %19, i64* %16
%22 = load i32, i32* %6
%23 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
store i32 %22, i32* %23
%24 = load i32, i32* %7
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 1
store i32 %24, i32* %25
%26 = load i32, i32* %8
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 2
store i32 %26, i32* %27
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
%29 = load double*, double** %17
%30 = call i32 @_ada_use_c2phc(i32 224, i32* %28, i32* %21, double* %29)
store i32 %30, i32* %12
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
%32 = load i32, i32* %31
%33 = load i32*, i32** %9
store i32 %32, i32* %33
store i32 0, i32* %11
br label %34
34: ; preds = %49, %5
%35 = load i32, i32* %11
%36 = load i32*, i32** %9
%37 = load i32, i32* %36
%38 = icmp slt i32 %35, %37
br i1 %38, label %39, label %52
39: ; preds = %34
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %21, i64 %41
%43 = load i32, i32* %42
%44 = trunc i32 %43 to i8
%45 = load i8*, i8** %10
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 %44, i8* %48
br label %49
49: ; preds = %39
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %34
52: ; preds = %34
%53 = load i8*, i8** %10
%54 = load i32*, i32** %9
%55 = load i32, i32* %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 0, i8* %57
%58 = load i32, i32* %12
%59 = load i8*, i8** %15
ret i32 %58
}

LLVM IR (-O2):
define i32 @localization_poset(i32 %0, i32 %1, i32 %2, i32* nocapture %3, i8* nocapture writeonly %4) {
%6 = alloca [3 x i32]
%7 = bitcast [3 x i32]* %6 to i8*
%8 = tail call i8* @llvm.stacksave()
%9 = alloca [10240 x i32]
%10 = getelementptr inbounds [10240 x i32], [10240 x i32]* %9, i64 0, i64 0
%11 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
store i32 %0, i32* %11
%12 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 1
store i32 %1, i32* %12
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 2
store i32 %2, i32* %13
%14 = call i32 @_ada_use_c2phc(i32 224, i32* %11, i32* %10, double* undef)
%15 = load i32, i32* %11
store i32 %15, i32* %3
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %5, %17
%18 = phi i64 [ %23, %17 ], [ 0, %5 ]
%19 = getelementptr inbounds [10240 x i32], [10240 x i32]* %9, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %4, i64 %18
store i8 %21, i8* %22
%23 = add nuw nsw i64 %18, 1
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %17, label %27
27: ; preds = %17, %5
%28 = phi i32 [ %15, %5 ], [ %24, %17 ]
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %4, i64 %29
store i8 0, i8* %30
ret i32 %14
}