#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 */
typedef int /*<<< orphan*/ subject;
typedef int /*<<< orphan*/ expected;

/* Variables and functions */
int inter_change(int **, int, int);
int /*<<< orphan*/ printf(char *, ...);
char *test_inter_change() {
  int subject[] = {1, 2, 3, 4, 5};
  int result = inter_change(&subject, 1, 2);
  int expected[] = {1, 3, 2, 4, 5};
  for (int i = 0, n = sizeof(subject) / sizeof(int); i < n; i++) {
    printf("%i, ", subject[i]);
  }
  printf("\n");
  for (int i = 0, n = sizeof(expected) / sizeof(int); i < n; i++) {
    printf("%i, ", expected[i]);
  }
  printf("\n");
  do {
    if (!(subject == expected))
      return "interchange switched two valid positions";
  } while (0);
  do {
    if (!(result == 0))
      return "interchange return success";
  } while (0);
  result = inter_change(&subject, 0, 6);
  do {
    if (!(result == 1))
      return "interchange returned out of bounds error";
  } while (0);
  do {
    if (!(subject[1] == 3))
      return "interchange didn't modify the array";
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<test_inter_change>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecc(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1040 <inter_change@plt>
mov    %eax,-0x24(%rbp)
mov    0xebc(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeb9(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xeb7(%rip),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x5,-0x48(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    11ba <test_inter_change+0x9a>
movslq -0x44(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    118a <test_inter_change+0x6a>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4c(%rbp)
movl   $0x5,-0x50(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    1206 <test_inter_change+0xe6>
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11d6 <test_inter_change+0xb6>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe20(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_inter_change>:
push   %rbx
sub    $0x20,%rsp
mov    0xed5(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <inter_change@plt>
mov    (%rsp),%esi
lea    0xeae(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe0b(%rip),%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_inter_change.subject = [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5]
@__const.test_inter_change.expected = [5 x i32] [i32 1, i32 3, i32 2, i32 4, i32 5]
@.str = [5 x i8] c"%i, \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [41 x i8] c"interchange switched two valid positions\00"
@.str.3 = [27 x i8] c"interchange return success\00"
@.str.4 = [41 x i8] c"interchange returned out of bounds error\00"
@.str.5 = [36 x i8] c"interchange didn't modify the array\00"
define i8* @test_inter_change() {
%1 = alloca i8*
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = alloca [5 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast [5 x i32]* %2 to i8*
%10 = bitcast [5 x i32]* %2 to i32**
%11 = call i32 @inter_change(i32** %10, i32 1, i32 2)
store i32 %11, i32* %3
%12 = bitcast [5 x i32]* %4 to i8*
store i32 0, i32* %5
store i32 5, i32* %6
br label %13
13: ; preds = %23, %0
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %17
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %13
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
store i32 5, i32* %8
br label %28
28: ; preds = %38, %26
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %32
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %28
41: ; preds = %28
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %66
44: ; No predecessors!
br label %45
45: ; preds = %44
%46 = load i32, i32* %3
%47 = icmp eq i32 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %45
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %66
49: ; preds = %45
br label %50
50: ; preds = %49
%51 = bitcast [5 x i32]* %2 to i32**
%52 = call i32 @inter_change(i32** %51, i32 0, i32 6)
store i32 %52, i32* %3
br label %53
53: ; preds = %50
%54 = load i32, i32* %3
%55 = icmp eq i32 %54, 1
br i1 %55, label %57, label %56
56: ; preds = %53
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8** %1
br label %66
57: ; preds = %53
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
%60 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 1
%61 = load i32, i32* %60
%62 = icmp eq i32 %61, 3
br i1 %62, label %64, label %63
63: ; preds = %59
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %66
64: ; preds = %59
br label %65
65: ; preds = %64
store i8* null, i8** %1
br label %66
66: ; preds = %65, %63, %56, %48, %43
%67 = load i8*, i8** %1
ret i8* %67
}

LLVM IR (-O2):
@__const.test_inter_change.subject = [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5]
@.str = [5 x i8] c"%i, \00"
@.str.2 = [41 x i8] c"interchange switched two valid positions\00"
define i8* @test_inter_change() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = bitcast [5 x i32]* %1 to i32**
%4 = call i32 @inter_change(i32** %3, i32 1, i32 2)
%5 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%6 = load i32, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
%9 = load i32, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 2
%12 = load i32, i32* %11
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 4
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @putchar(i32 10)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 3)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 2)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 5)
%26 = call i32 @putchar(i32 10)
ret i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0)
}