#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*/ retrieve_and_write(int, int);
int /*<<< orphan*/ scanf(char *, int *);
int solcon_replace_standard_solution(int, int, int, double *);
void test_replace_solution(int n) {
  int i, k, m, fail;
  double sol[2 * n + 5];
  printf("Give k : ");
  scanf("%d", &k);
  retrieve_and_write(n, k);
  printf("Setting solution vector to 1,2,3,...\n");
  sol[0] = 1.111;
  sol[1] = 2.222;
  m = 12345;
  sol[2 * n + 2] = 3.333;
  sol[2 * n + 3] = 4.444;
  sol[2 * n + 4] = 5.555;
  for (i = 0; i < 2 * n; i++)
    sol[2 + i] = i;
  fail = solcon_replace_standard_solution(n, k, m, sol);
  if (fail == 1)
    printf("some failure occurred...\n");
  else {
    printf("The changed solution retrieved again :\n");
    retrieve_and_write(n, k);
  }
}


x86 assembly (clang, -O0):
<test_replace_solution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
mov    %ecx,%eax
lea    0x5(%rax,%rax,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
lea    0xea7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <retrieve_and_write@plt>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
movsd  0xe69(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  0xe55(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
movl   $0x3039,-0x10(%rbp)
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  0xe2d(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movsd  0xe0c(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
movsd  0xdeb(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    1257 <test_replace_solution+0x117>
mov    -0x30(%rbp),%rax
cvtsi2sdl -0x8(%rbp),%xmm0
mov    -0x8(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1221 <test_replace_solution+0xe1>
mov    -0x30(%rbp),%rcx
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <solcon_replace_standard_solution@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1287 <test_replace_solution+0x147>
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
jmp    129e <test_replace_solution+0x15e>
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <retrieve_and_write@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_replace_solution>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
mov    %rsp,-0x38(%rbp)
lea    (%r14,%r14,1),%r12d
lea    (%r14,%r14,1),%eax
add    $0x5,%eax
lea    0xf(,%rax,8),%r13
and    $0xfffffffffffffff0,%r13
mov    %rsp,%r15
mov    %r15,%rbx
sub    %r13,%rbx
neg    %r13
mov    %rbx,%rsp
lea    0xedb(%rip),%rdi
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x2c(%rbp),%esi
mov    %r14d,%edi
call   1060 <retrieve_and_write@plt>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
movaps 0xe38(%rip),%xmm0
movaps %xmm0,(%r15,%r13,1)
movdqa 0xe3b(%rip),%xmm0
movslq %r12d,%rax
movdqa %xmm0,0x10(%rbx,%rax,8)
movabs $0x40163851eb851eb8,%rcx
38 16 40
mov    %rcx,0x20(%rbx,%rax,8)
test   %r14d,%r14d
jle    12f6 <test_replace_solution+0x1a6>
cmp    $0x2,%r12d
mov    $0x1,%eax
cmovge %r12d,%eax
cmp    $0x4,%eax
jae    120f <test_replace_solution+0xbf>
xor    %ecx,%ecx
jmp    12e0 <test_replace_solution+0x190>
mov    %eax,%ecx
and    $0x7ffffffc,%ecx
lea    -0x4(%rcx),%rsi
mov    %rsi,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     1346 <test_replace_solution+0x1f6>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
movdqa 0xde2(%rip),%xmm0
mov    $0x2,%esi
movdqa 0xde5(%rip),%xmm1
movdqa 0xded(%rip),%xmm2
movdqa 0xdf5(%rip),%xmm3
movdqa 0xdfd(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqa %xmm0,%xmm5
cvtdq2pd %xmm0,%xmm6
paddd  %xmm1,%xmm5
cvtdq2pd %xmm5,%xmm5
movaps %xmm6,(%rbx,%rsi,8)
movaps %xmm5,0x10(%rbx,%rsi,8)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
cvtdq2pd %xmm5,%xmm5
paddd  %xmm3,%xmm6
cvtdq2pd %xmm6,%xmm6
movaps %xmm5,0x20(%rbx,%rsi,8)
movaps %xmm6,0x30(%rbx,%rsi,8)
paddd  %xmm4,%xmm0
add    $0x8,%rsi
add    $0xfffffffffffffffe,%rdi
jne    1270 <test_replace_solution+0x120>
test   $0x1,%dl
je     12d9 <test_replace_solution+0x189>
cvtdq2pd %xmm0,%xmm1
paddd  0xd66(%rip),%xmm0
cvtdq2pd %xmm0,%xmm0
movdqa %xmm1,(%rbx,%rsi,8)
movdqa %xmm0,0x10(%rbx,%rsi,8)
cmp    %rax,%rcx
je     12f6 <test_replace_solution+0x1a6>
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x10(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    12e0 <test_replace_solution+0x190>
mov    -0x2c(%rbp),%esi
mov    %r14d,%edi
mov    $0x3039,%edx
mov    %rbx,%rcx
call   1050 <solcon_replace_standard_solution@plt>
cmp    $0x1,%eax
jne    131c <test_replace_solution+0x1cc>
lea    0xdb4(%rip),%rdi
call   1030 <puts@plt>
jmp    1333 <test_replace_solution+0x1e3>
lea    0xd7f(%rip),%rdi
call   1030 <puts@plt>
mov    -0x2c(%rbp),%esi
mov    %r14d,%edi
call   1060 <retrieve_and_write@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movdqa 0xcd2(%rip),%xmm0
mov    $0x2,%esi
test   $0x1,%dl
jne    12be <test_replace_solution+0x16e>
jmp    12d9 <test_replace_solution+0x189>

LLVM IR (-O0):
@.str = [10 x i8] c"Give k : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"Setting solution vector to 1,2,3,...\0A\00"
@.str.3 = [26 x i8] c"some failure occurred...\0A\00"
@.str.4 = [40 x i8] c"The changed solution retrieved again :\0A\00"
define void @test_replace_solution(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %2
%9 = load i32, i32* %2
%10 = mul nsw i32 2, %9
%11 = add nsw i32 %10, 5
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca double, i64 %12
store i64 %12, i64* %8
%15 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%17 = load i32, i32* %2
%18 = load i32, i32* %4
%19 = call i32 @retrieve_and_write(i32 %17, i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds double, double* %14, i64 0
store double 1.111000e+00, double* %21
%22 = getelementptr inbounds double, double* %14, i64 1
store double 2.222000e+00, double* %22
store i32 12345, i32* %5
%23 = load i32, i32* %2
%24 = mul nsw i32 2, %23
%25 = add nsw i32 %24, 2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %14, i64 %26
store double 3.333000e+00, double* %27
%28 = load i32, i32* %2
%29 = mul nsw i32 2, %28
%30 = add nsw i32 %29, 3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %14, i64 %31
store double 4.444000e+00, double* %32
%33 = load i32, i32* %2
%34 = mul nsw i32 2, %33
%35 = add nsw i32 %34, 4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %14, i64 %36
store double 5.555000e+00, double* %37
store i32 0, i32* %3
br label %38
38: ; preds = %50, %1
%39 = load i32, i32* %3
%40 = load i32, i32* %2
%41 = mul nsw i32 2, %40
%42 = icmp slt i32 %39, %41
br i1 %42, label %43, label %53
43: ; preds = %38
%44 = load i32, i32* %3
%45 = sitofp i32 %44 to double
%46 = load i32, i32* %3
%47 = add nsw i32 2, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %14, i64 %48
store double %45, double* %49
br label %50
50: ; preds = %43
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %38
53: ; preds = %38
%54 = load i32, i32* %2
%55 = load i32, i32* %4
%56 = load i32, i32* %5
%57 = call i32 @solcon_replace_standard_solution(i32 %54, i32 %55, i32 %56, double* %14)
store i32 %57, i32* %6
%58 = load i32, i32* %6
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %62
60: ; preds = %53
%61 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %67
62: ; preds = %53
%63 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%64 = load i32, i32* %2
%65 = load i32, i32* %4
%66 = call i32 @retrieve_and_write(i32 %64, i32 %65)
br label %67
67: ; preds = %62, %60
%68 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"Give k : \00"
@.str.1 = [3 x i8] c"%d\00"
@str = [37 x i8] c"Setting solution vector to 1,2,3,...\00"
@str.5 = [39 x i8] c"The changed solution retrieved again :\00"
@str.6 = [25 x i8] c"some failure occurred...\00"
define void @test_replace_solution(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = shl i32 %0, 1
%5 = add nsw i32 %4, 5
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca double, i64 %6
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = call i32 @retrieve_and_write(i32 %0, i32 %11)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%14 = bitcast double* %8 to <2 x double>*
store <2 x double> <double 1.111000e+00, double 2.222000e+00>, <2 x double>* %14
%15 = add nsw i32 %4, 2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %8, i64 %16
%18 = bitcast double* %17 to <2 x double>*
store <2 x double> <double 3.333000e+00, double 4.444000e+00>, <2 x double>* %18
%19 = add nsw i32 %4, 4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %8, i64 %20
store double 5.555000e+00, double* %21
%22 = icmp sgt i32 %0, 0
br i1 %22, label %23, label %87
23: ; preds = %1
%24 = call i32 @llvm.smax.i32(i32 %4, i32 1)
%25 = zext i32 %24 to i64
%26 = icmp ult i32 %24, 4
br i1 %26, label %77, label %27
27: ; preds = %23
%28 = and i64 %25, 2147483644
%29 = add nsw i64 %28, -4
%30 = lshr exact i64 %29, 2
%31 = add nuw nsw i64 %30, 1
%32 = and i64 %31, 1
%33 = icmp eq i64 %29, 0
br i1 %33, label %63, label %34
34: ; preds = %27
%35 = and i64 %31, 9223372036854775806
br label %36
36: ; preds = %36, %34
%37 = phi i64 [ 0, %34 ], [ %57, %36 ]
%38 = phi <2 x i32> [ <i32 0, i32 1>, %34 ], [ %58, %36 ]
%39 = phi i64 [ 0, %34 ], [ %59, %36 ]
%40 = add <2 x i32> %38, <i32 2, i32 2>
%41 = sitofp <2 x i32> %38 to <2 x double>
%42 = sitofp <2 x i32> %40 to <2 x double>
%43 = or i64 %37, 2
%44 = getelementptr inbounds double, double* %8, i64 %43
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> %41, <2 x double>* %45
%46 = getelementptr inbounds double, double* %44, i64 2
%47 = bitcast double* %46 to <2 x double>*
store <2 x double> %42, <2 x double>* %47
%48 = add <2 x i32> %38, <i32 4, i32 4>
%49 = add <2 x i32> %38, <i32 6, i32 6>
%50 = sitofp <2 x i32> %48 to <2 x double>
%51 = sitofp <2 x i32> %49 to <2 x double>
%52 = or i64 %37, 6
%53 = getelementptr inbounds double, double* %8, i64 %52
%54 = bitcast double* %53 to <2 x double>*
store <2 x double> %50, <2 x double>* %54
%55 = getelementptr inbounds double, double* %53, i64 2
%56 = bitcast double* %55 to <2 x double>*
store <2 x double> %51, <2 x double>* %56
%57 = add nuw i64 %37, 8
%58 = add <2 x i32> %38, <i32 8, i32 8>
%59 = add i64 %39, 2
%60 = icmp eq i64 %59, %35
br i1 %60, label %61, label %36
61: ; preds = %36
%62 = or i64 %57, 2
br label %63
63: ; preds = %61, %27
%64 = phi i64 [ 2, %27 ], [ %62, %61 ]
%65 = phi <2 x i32> [ <i32 0, i32 1>, %27 ], [ %58, %61 ]
%66 = icmp eq i64 %32, 0
br i1 %66, label %75, label %67
67: ; preds = %63
%68 = add <2 x i32> %65, <i32 2, i32 2>
%69 = sitofp <2 x i32> %65 to <2 x double>
%70 = sitofp <2 x i32> %68 to <2 x double>
%71 = getelementptr inbounds double, double* %8, i64 %64
%72 = bitcast double* %71 to <2 x double>*
store <2 x double> %69, <2 x double>* %72
%73 = getelementptr inbounds double, double* %71, i64 2
%74 = bitcast double* %73 to <2 x double>*
store <2 x double> %70, <2 x double>* %74
br label %75
75: ; preds = %63, %67
%76 = icmp eq i64 %28, %25
br i1 %76, label %87, label %77
77: ; preds = %23, %75
%78 = phi i64 [ 0, %23 ], [ %28, %75 ]
br label %79
79: ; preds = %77, %79
%80 = phi i64 [ %85, %79 ], [ %78, %77 ]
%81 = trunc i64 %80 to i32
%82 = sitofp i32 %81 to double
%83 = add nuw nsw i64 %80, 2
%84 = getelementptr inbounds double, double* %8, i64 %83
store double %82, double* %84
%85 = add nuw nsw i64 %80, 1
%86 = icmp eq i64 %85, %25
br i1 %86, label %87, label %79
87: ; preds = %79, %75, %1
%88 = load i32, i32* %2
%89 = call i32 @solcon_replace_standard_solution(i32 %0, i32 %88, i32 12345, double* %8)
%90 = icmp eq i32 %89, 1
br i1 %90, label %91, label %93
91: ; preds = %87
%92 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
br label %97
93: ; preds = %87
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.5, i64 0, i64 0))
%95 = load i32, i32* %2
%96 = call i32 @retrieve_and_write(i32 %0, i32 %95)
br label %97
97: ; preds = %93, %91
ret void
}