#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sort(int *, int);
int main() {
  int a[4];
  a[0] = 5;
  a[1] = 3;
  a[2] = 7;
  a[3] = 4;
  printf("Original:\n");
  for (int i = 0; i < 4; i++) {
    printf("%d position %d\n", a[i], i);
  }
  sort(a, 4);
  printf("\nSorted:\n");
  for (int i = 0; i < 4; i++) {
    printf("%d position %d\n", a[i], i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x20(%rbp)
movl   $0x3,-0x1c(%rbp)
movl   $0x7,-0x18(%rbp)
movl   $0x4,-0x14(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1191 <main+0x71>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
mov    -0x24(%rbp),%edx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1160 <main+0x40>
lea    -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1040 <sort@plt>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    11e5 <main+0xc5>
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
mov    -0x28(%rbp),%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b4 <main+0x94>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movaps 0xec4(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xed9(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x4,%esi
call   1050 <sort@plt>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Original:\0A\00"
@.str.1 = [16 x i8] c"%d position %d\0A\00"
@.str.2 = [10 x i8] c"\0ASorted:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
store i32 5, i32* %5
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
store i32 3, i32* %6
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
store i32 7, i32* %7
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
store i32 4, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %10
10: ; preds = %20, %0
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
br label %20
20: ; preds = %13
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %10
23: ; preds = %10
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%25 = call i32 @sort(i32* %24, i32 4)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %27
27: ; preds = %37, %23
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 4
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %4
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %35)
br label %37
37: ; preds = %30
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %27
40: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"%d position %d\0A\00"
@str = [10 x i8] c"Original:\00"
@str.3 = [9 x i8] c"\0ASorted:\00"
define i32 @main() {
%1 = alloca <4 x i32>
%2 = bitcast <4 x i32>* %1 to i8*
%3 = getelementptr inbounds <4 x i32>, <4 x i32>* %1, i64 0, i64 0
%4 = getelementptr inbounds <4 x i32>, <4 x i32>* %1, i64 0, i64 1
%5 = getelementptr inbounds <4 x i32>, <4 x i32>* %1, i64 0, i64 2
%6 = getelementptr inbounds <4 x i32>, <4 x i32>* %1, i64 0, i64 3
store <4 x i32> <i32 5, i32 3, i32 7, i32 4>, <4 x i32>* %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 1)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 7, i32 2)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 3)
%12 = call i32 @sort(i32* %3, i32 4)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.3, i64 0, i64 0))
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 0)
%16 = load i32, i32* %4
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 1)
%18 = load i32, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 2)
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 3)
ret i32 0
}