#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 set_structure_string(int *nc, char *s) {
  int fail, i;
  int buffer[1024];
  double *c;
  fail = _ada_use_c2phc(116, nc, buffer, c);
  for (i = 0; i < *nc; i++)
    s[i] = (char)buffer[i];
  s[*nc] = '\0';
  return fail;
}


x86 assembly (clang, -O0):
<set_structure_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x1020(%rbp),%rdx
mov    -0x1028(%rbp),%rcx
mov    $0x74,%edi
call   1030 <_ada_use_c2phc@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    117e <set_structure_string+0x6e>
movslq -0x18(%rbp),%rax
mov    -0x1020(%rbp,%rax,4),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1149 <set_structure_string+0x39>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_structure_string>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdx
mov    $0x74,%edi
mov    %rbx,%rsi
call   1030 <_ada_use_c2phc@plt>
mov    (%rbx),%ecx
test   %ecx,%ecx
jle    1154 <set_structure_string+0x44>
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%rdx,4),%ecx
mov    %cl,(%r14,%rdx,1)
add    $0x1,%rdx
movslq (%rbx),%rcx
cmp    %rcx,%rdx
jl     1140 <set_structure_string+0x30>
movslq %ecx,%rcx
movb   $0x0,(%r14,%rcx,1)
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

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

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