#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int scanf(char *, double *, char *);
int /*<<< orphan*/ stdin;
void getMatrixValues(double matrix[], int size[2]) {
  for (int i = 0; i < size[0]; i++)
    for (int j = 0; j < size[1]; j++) {
      int inputinvalid;
      double element;
      char c;
      do {
        printf("Element %d,%d: ", i + 1, j + 1);
        inputinvalid = scanf("%lf%c", &element, &c) != 2 || c != '\n';
        fflush(stdin);
      } while (inputinvalid);
      matrix[i * size[1] + j] = element;
    }
}


x86 assembly (clang, -O0):
<getMatrixValues>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    121e <getMatrixValues+0xee>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    0x4(%rcx),%eax
jge    120b <getMatrixValues+0xdb>
jmp    1172 <getMatrixValues+0x42>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
lea    0xe7f(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x29(%rbp),%rdx
call   1050 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x2,%ecx
mov    %al,-0x2a(%rbp)
jne    11bb <getMatrixValues+0x8b>
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1172 <getMatrixValues+0x42>
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rdx
imul   0x4(%rdx),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115d <getMatrixValues+0x2d>
jmp    1210 <getMatrixValues+0xe0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1147 <getMatrixValues+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMatrixValues>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    (%rsi),%ecx
test   %ecx,%ecx
jle    1223 <getMatrixValues+0xf3>
mov    0x10(%rsp),%rax
mov    0x4(%rax),%eax
xor    %esi,%esi
lea    0xf(%rsp),%rbp
mov    0x2e80(%rip),%r13
jmp    117c <getMatrixValues+0x4c>
nopw   0x0(%rax,%rax,1)
mov    %r14d,%esi
cmp    %ecx,%r14d
jge    1223 <getMatrixValues+0xf3>
lea    0x1(%rsi),%r14d
test   %eax,%eax
jle    1170 <getMatrixValues+0x40>
xor    %ecx,%ecx
mov    %rsi,0x20(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %rcx,0x28(%rsp)
lea    0x1(%rcx),%r15d
nopl   0x0(%rax)
lea    0xe59(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
call   1030 <printf@plt>
lea    0xe57(%rip),%rdi
lea    0x30(%rsp),%rsi
mov    %rbp,%rdx
call   1050 <scanf@plt>
mov    %eax,%r12d
movzbl 0xf(%rsp),%ebx
mov    0x0(%r13),%edi
call   1040 <fflush@plt>
cmp    $0x2,%r12d
jne    11a0 <getMatrixValues+0x70>
cmp    $0xa,%bl
jne    11a0 <getMatrixValues+0x70>
movsd  0x30(%rsp),%xmm0
mov    0x10(%rsp),%rax
mov    0x4(%rax),%eax
mov    %eax,%ecx
mov    0x20(%rsp),%rsi
imul   %esi,%ecx
add    0x28(%rsp),%ecx
movslq %ecx,%rcx
mov    0x18(%rsp),%rdx
movsd  %xmm0,(%rdx,%rcx,8)
mov    %r15d,%ecx
cmp    %eax,%r15d
jl     1190 <getMatrixValues+0x60>
mov    0x10(%rsp),%rcx
mov    (%rcx),%ecx
jmp    1170 <getMatrixValues+0x40>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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