#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 */
scalar_t__ get_input(char const *, int *, int **);
int /*<<< orphan*/ printf(char *, ...);
int demo(const char *filename, void fn(int *, int)) {
  int *p, n, i;
  if (get_input(filename, &n, &p)) {
    return 1;
  }
  printf("before:");
  for (i = 0; i < n; i++) {
    printf(" %d", p[i]);
  }
  printf("\n");
  fn(p, n);
  printf("after :");
  for (i = 0; i < n; i++) {
    printf(" %d", p[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<demo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <get_input@plt>
cmp    $0x0,%rax
je     1157 <demo+0x37>
movl   $0x1,-0x4(%rbp)
jmp    1217 <demo+0xf7>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    119f <demo+0x7f>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    116c <demo+0x4c>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   *%rax
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1202 <demo+0xe2>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11cf <demo+0xaf>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<demo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1050 <get_input@plt>
mov    $0x1,%r15d
test   %rax,%rax
jne    120a <demo+0xda>
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11a0 <demo+0x70>
lea    0xe91(%rip),%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1180 <demo+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
call   *%r14
lea    0xe4f(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1200 <demo+0xd0>
lea    0xe33(%rip),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    (%rax,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     11e0 <demo+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"before:\00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [8 x i8] c"after :\00"
define i32 @demo(i8* %0, void (i32*, i32)* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca void (i32*, i32)*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store void (i32*, i32)* %1, void (i32*, i32)** %5
%9 = load i8*, i8** %4
%10 = call i64 @get_input(i8* %9, i32* %7, i32** %6)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %51
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %15
15: ; preds = %26, %13
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %19
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %15
29: ; preds = %15
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%31 = load void (i32*, i32)*, void (i32*, i32)** %5
%32 = load i32*, i32** %6
%33 = load i32, i32* %7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
br label %35
35: ; preds = %46, %29
%36 = load i32, i32* %8
%37 = load i32, i32* %7
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %49
39: ; preds = %35
%40 = load i32*, i32** %6
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %39
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %35
49: ; preds = %35
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %51
51: ; preds = %49, %12
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [8 x i8] c"before:\00"
@.str.1 = [4 x i8] c" %d\00"
@.str.3 = [8 x i8] c"after :\00"
define i32 @demo(i8* %0, void (i32*, i32)* nocapture %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = bitcast i32** %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i64 @get_input(i8* %0, i32* %4, i32** %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %42
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %9, %13
%14 = phi i64 [ %19, %13 ], [ 0, %9 ]
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 %14
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i64 %14, 1
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %13, label %23
23: ; preds = %13, %9
%24 = call i32 @putchar(i32 10)
%25 = load i32*, i32** %3
%26 = load i32, i32* %4
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %23, %30
%31 = phi i64 [ %36, %30 ], [ 0, %23 ]
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i64 %31
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = add nuw nsw i64 %31, 1
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %30, label %40
40: ; preds = %30, %23
%41 = call i32 @putchar(i32 10)
br label %42
42: ; preds = %2, %40
%43 = phi i32 [ 0, %40 ], [ 1, %2 ]
ret i32 %43
}