#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 *, ...);
double *findMinMax(double *a, double *minmax, int size) {
  printf("setting minmax\n");
  minmax[0] = a[0];
  minmax[1] = a[0];
  printf("forlooptraversal\n");
  for (int i = 1; i < size; i++) {
    printf("%d:", i);
    if (a[i] > minmax[1])
      minmax[1] = a[i];
    if (a[i] < minmax[0])
      minmax[0] = a[i];
  }
  printf("succ\n");
  return minmax;
}


x86 assembly (clang, -O0):
<findMinMax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fd <findMinMax+0xed>
mov    -0x18(%rbp),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
ucomisd 0x8(%rax),%xmm0
jbe    11b6 <findMinMax+0xa6>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ea <findMinMax+0xda>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    11ef <findMinMax+0xdf>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1167 <findMinMax+0x57>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findMinMax>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
movsd  (%r14),%xmm0
movsd  %xmm0,(%r15)
movsd  (%r14),%xmm0
movsd  %xmm0,0x8(%r15)
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x2,%ebx
jl     11c1 <findMinMax+0xa1>
mov    %ebx,%r13d
mov    $0x1,%ebx
lea    0xe8e(%rip),%r12
jmp    1189 <findMinMax+0x69>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%r13
je     11c1 <findMinMax+0xa1>
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  (%r14,%rbx,8),%xmm0
ucomisd 0x8(%r15),%xmm0
jbe    11af <findMinMax+0x8f>
movsd  %xmm0,0x8(%r15)
movsd  (%r14,%rbx,8),%xmm0
movsd  (%r15),%xmm1
ucomisd %xmm0,%xmm1
jbe    1180 <findMinMax+0x60>
movsd  %xmm0,(%r15)
jmp    1180 <findMinMax+0x60>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"setting minmax\0A\00"
@.str.1 = [18 x i8] c"forlooptraversal\0A\00"
@.str.2 = [4 x i8] c"%d:\00"
@.str.3 = [6 x i8] c"succ\0A\00"
define double* @findMinMax(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = load double*, double** %4
%10 = getelementptr inbounds double, double* %9, i64 0
%11 = load double, double* %10
%12 = load double*, double** %5
%13 = getelementptr inbounds double, double* %12, i64 0
store double %11, double* %13
%14 = load double*, double** %4
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = load double*, double** %5
%18 = getelementptr inbounds double, double* %17, i64 1
store double %16, double* %18
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %7
br label %20
20: ; preds = %63, %3
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %66
24: ; preds = %20
%25 = load i32, i32* %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load double*, double** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = load double*, double** %5
%33 = getelementptr inbounds double, double* %32, i64 1
%34 = load double, double* %33
%35 = fcmp ogt double %31, %34
br i1 %35, label %36, label %44
36: ; preds = %24
%37 = load double*, double** %4
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = load double*, double** %5
%43 = getelementptr inbounds double, double* %42, i64 1
store double %41, double* %43
br label %44
44: ; preds = %36, %24
%45 = load double*, double** %4
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = load double*, double** %5
%51 = getelementptr inbounds double, double* %50, i64 0
%52 = load double, double* %51
%53 = fcmp olt double %49, %52
br i1 %53, label %54, label %62
54: ; preds = %44
%55 = load double*, double** %4
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = load double*, double** %5
%61 = getelementptr inbounds double, double* %60, i64 0
store double %59, double* %61
br label %62
62: ; preds = %54, %44
br label %63
63: ; preds = %62
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %20
66: ; preds = %20
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%68 = load double*, double** %5
ret double* %68
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c"%d:\00"
@str = [15 x i8] c"setting minmax\00"
@str.4 = [17 x i8] c"forlooptraversal\00"
@str.5 = [5 x i8] c"succ\00"
define double* @findMinMax(double* nocapture %0, double* returned %1, i32 %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%5 = load double, double* %0
store double %5, double* %1
%6 = load double, double* %0
%7 = getelementptr inbounds double, double* %1, i64 1
store double %6, double* %7
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
%9 = icmp sgt i32 %2, 1
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = zext i32 %2 to i64
br label %14
12: ; preds = %29, %3
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
ret double* %1
14: ; preds = %10, %29
%15 = phi i64 [ 1, %10 ], [ %30, %29 ]
%16 = trunc i64 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds double, double* %0, i64 %15
%19 = load double, double* %18
%20 = load double, double* %7
%21 = fcmp ogt double %19, %20
br i1 %21, label %22, label %24
22: ; preds = %14
store double %19, double* %7
%23 = load double, double* %18
br label %24
24: ; preds = %22, %14
%25 = phi double [ %23, %22 ], [ %19, %14 ]
%26 = load double, double* %1
%27 = fcmp olt double %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store double %25, double* %1
br label %29
29: ; preds = %24, %28
%30 = add nuw nsw i64 %15, 1
%31 = icmp eq i64 %30, %11
br i1 %31, label %12, label %14
}