#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 /*<<< orphan*/ adafinal();
int /*<<< orphan*/ adainit();
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(int *);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(int argc, char *argv[]) {
  double *c;
  int fail, choice, i;
  char skip_newline, ch;
  printf("\nTesting if phc can C strings...\n");
  adainit();
  {
    int n, *s;
    do {
      printf("Give the number of elements : ");
      scanf("%d", &n);
      s = (int *)calloc(n, sizeof(int));
      skip_newline = getchar();
      printf("Give %d characters : ", n);
      for (i = 0; i < n; i++) {
        scanf("%c", &ch);
        s[i] = (int)ch;
      }
      printf("The array of integers : ");
      for (i = 0; i < n; i++)
        printf(" %d", s[i]);
      printf("\n");
      printf("The array of characters : ");
      for (i = 0; i < n; i++) {
        ch = (char)s[i];
        printf(" %c", ch);
      }
      printf("\n");
      fail = _ada_use_c2phc(158, &n, s, c);
      printf("use_c2phc returned %d as fail value\n", fail);
      printf("Give a number (1 to continue, 0 to exit) : ");
      scanf("%d", &choice);
      skip_newline = getchar();
      free(s);
    } while (choice > 0);
  }
  adafinal();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10a0 <adainit@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
mov    -0x2c(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x25(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1239 <main+0xb9>
lea    0xe7f(%rip),%rdi
lea    -0x26(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
movsbl -0x26(%rbp),%edx
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fe <main+0x7e>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1281 <main+0x101>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    124e <main+0xce>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12de <main+0x15e>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,-0x26(%rbp)
movsbl -0x26(%rbp),%esi
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12a4 <main+0x124>
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x9e,%edi
lea    -0x2c(%rbp),%rsi
call   1080 <_ada_use_c2phc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd46(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x25(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
jg     11ab <main+0x2b>
mov    $0x0,%al
call   1070 <adafinal@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xf0d(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   10c0 <adainit@plt>
lea    0xe87(%rip),%rbp
lea    0x10(%rsp),%rbx
lea    0xe7a(%rip),%r12
lea    0xe92(%rip),%r14
jmp    124d <main+0xad>
nopl   (%rax)
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    $0x9e,%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <_ada_use_c2phc@plt>
lea    0xe6b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2b(%rip),%rbp
mov    %rbp,%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
cmpl   $0x0,0x14(%rsp)
jle    1368 <main+0x1c8>
lea    0xdac(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
mov    0x10(%rsp),%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0x10(%rsp),%esi
lea    0xd94(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0x10(%rsp)
lea    0xdd0(%rip),%r13
lea    0xf(%rsp),%rbp
jle    12d4 <main+0x134>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
movsbl 0xf(%rsp),%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
movslq 0x10(%rsp),%rax
cmp    %rax,%rbx
jl     12b0 <main+0x110>
lea    0xd5a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0x10(%rsp)
jle    130c <main+0x16c>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq 0x10(%rsp),%rax
cmp    %rax,%rbx
jl     12f0 <main+0x150>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xd35(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0x10(%rsp)
jle    11e0 <main+0x40>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15,%r13,4),%eax
mov    %al,0xf(%rsp)
movsbl %al,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r13
movslq 0x10(%rsp),%rax
cmp    %rax,%r13
jl     1340 <main+0x1a0>
jmp    11e0 <main+0x40>
xor    %eax,%eax
call   1090 <adafinal@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"\0ATesting if phc can C strings...\0A\00"
@.str.1 = [31 x i8] c"Give the number of elements : \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"Give %d characters : \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [25 x i8] c"The array of integers : \00"
@.str.6 = [4 x i8] c" %d\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [27 x i8] c"The array of characters : \00"
@.str.9 = [4 x i8] c" %c\00"
@.str.10 = [37 x i8] c"use_c2phc returned %d as fail value\0A\00"
@.str.11 = [44 x i8] c"Give a number (1 to continue, 0 to exit) : \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
%12 = alloca i32
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (...) @adainit()
br label %16
16: ; preds = %88, %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%19 = load i32, i32* %12
%20 = call i64 @calloc(i32 %19, i32 4)
%21 = inttoptr i64 %20 to i32*
store i32* %21, i32** %13
%22 = call signext i8 (...) @getchar()
store i8 %22, i8* %10
%23 = load i32, i32* %12
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %23)
store i32 0, i32* %9
br label %25
25: ; preds = %37, %16
%26 = load i32, i32* %9
%27 = load i32, i32* %12
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %40
29: ; preds = %25
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%31 = load i8, i8* %11
%32 = sext i8 %31 to i32
%33 = load i32*, i32** %13
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
br label %37
37: ; preds = %29
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %25
40: ; preds = %25
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %9
br label %42
42: ; preds = %53, %40
%43 = load i32, i32* %9
%44 = load i32, i32* %12
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %56
46: ; preds = %42
%47 = load i32*, i32** %13
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %46
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %42
56: ; preds = %42
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %9
br label %59
59: ; preds = %73, %56
%60 = load i32, i32* %9
%61 = load i32, i32* %12
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %76
63: ; preds = %59
%64 = load i32*, i32** %13
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = trunc i32 %68 to i8
store i8 %69, i8* %11
%70 = load i8, i8* %11
%71 = sext i8 %70 to i32
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %63
%74 = load i32, i32* %9
%75 = add nsw i32 %74, 1
store i32 %75, i32* %9
br label %59
76: ; preds = %59
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%78 = load i32*, i32** %13
%79 = load double*, double** %6
%80 = call i32 @_ada_use_c2phc(i32 158, i32* %12, i32* %78, double* %79)
store i32 %80, i32* %7
%81 = load i32, i32* %7
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %81)
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0))
%84 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%85 = call signext i8 (...) @getchar()
store i8 %85, i8* %10
%86 = load i32*, i32** %13
%87 = call i32 @free(i32* %86)
br label %88
88: ; preds = %76
%89 = load i32, i32* %8
%90 = icmp sgt i32 %89, 0
br i1 %90, label %16, label %91
91: ; preds = %88
%92 = call i32 (...) @adafinal()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [31 x i8] c"Give the number of elements : \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"Give %d characters : \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [25 x i8] c"The array of integers : \00"
@.str.6 = [4 x i8] c" %d\00"
@.str.8 = [27 x i8] c"The array of characters : \00"
@.str.9 = [4 x i8] c" %c\00"
@.str.10 = [37 x i8] c"use_c2phc returned %d as fail value\0A\00"
@.str.11 = [44 x i8] c"Give a number (1 to continue, 0 to exit) : \00"
@str = [33 x i8] c"\0ATesting if phc can C strings...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (...) @adainit()
%9 = bitcast i32* %5 to i8*
br label %10
10: ; preds = %61, %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%13 = load i32, i32* %5
%14 = call i64 @calloc(i32 %13, i32 4)
%15 = inttoptr i64 %14 to i32*
%16 = call signext i8 (...) @getchar()
%17 = load i32, i32* %5
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %5
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %10, %21
%22 = phi i64 [ %27, %21 ], [ 0, %10 ]
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = getelementptr inbounds i32, i32* %15, i64 %22
store i32 %25, i32* %26
%27 = add nuw nsw i64 %22, 1
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %21, label %31
31: ; preds = %21, %10
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32, i32* %5
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %31, %35
%36 = phi i64 [ %40, %35 ], [ 0, %31 ]
%37 = getelementptr inbounds i32, i32* %15, i64 %36
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %38)
%40 = add nuw nsw i64 %36, 1
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = icmp slt i64 %40, %42
br i1 %43, label %35, label %44
44: ; preds = %35, %31
%45 = call i32 @putchar(i32 10)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%47 = load i32, i32* %5
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %61
49: ; preds = %44, %49
%50 = phi i64 [ %57, %49 ], [ 0, %44 ]
%51 = getelementptr inbounds i32, i32* %15, i64 %50
%52 = load i32, i32* %51
%53 = trunc i32 %52 to i8
store i8 %53, i8* %4
%54 = shl i32 %52, 24
%55 = ashr exact i32 %54, 24
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %55)
%57 = add nuw nsw i64 %50, 1
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = icmp slt i64 %57, %59
br i1 %60, label %49, label %61
61: ; preds = %49, %44
%62 = call i32 @putchar(i32 10)
%63 = call i32 @_ada_use_c2phc(i32 158, i32* %5, i32* %15, double* undef)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0))
%66 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%67 = call signext i8 (...) @getchar()
%68 = call i32 @free(i32* %15)
%69 = load i32, i32* %3
%70 = icmp sgt i32 %69, 0
br i1 %70, label %10, label %71
71: ; preds = %61
%72 = call i32 (...) @adafinal()
ret i32 0
}