#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 */
size_t mat_to_arr(unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ swap_ints(int *, int *);
void swap_rows(int *arr, unsigned int row1, unsigned int row2,
               unsigned int rows, unsigned int columns) {
  for (unsigned int col = 1; col <= columns; col++)
    swap_ints(&arr[mat_to_arr(row1, col, columns)],
              &arr[mat_to_arr(row2, col, columns)]);
}


x86 assembly (clang, -O0):
<swap_rows>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
ja     11ac <swap_rows+0x8c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <mat_to_arr@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <mat_to_arr@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <swap_ints@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1140 <swap_rows+0x20>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_rows>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %r8d,%r8d
je     1182 <swap_rows+0x62>
mov    %r8d,%r13d
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%r12
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %ebp,%esi
mov    %r13d,%edx
call   1030 <mat_to_arr@plt>
lea    (%r12,%rax,4),%rbx
mov    %r14d,%edi
mov    %ebp,%esi
mov    %r13d,%edx
call   1030 <mat_to_arr@plt>
lea    (%r12,%rax,4),%rsi
mov    %rbx,%rdi
call   1040 <swap_ints@plt>
add    $0x1,%ebp
cmp    %r13d,%ebp
jbe    1150 <swap_rows+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @swap_rows(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 1, i32* %11
br label %12
12: ; preds = %30, %5
%13 = load i32, i32* %11
%14 = load i32, i32* %10
%15 = icmp ule i32 %13, %14
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = load i32*, i32** %6
%18 = load i32, i32* %7
%19 = load i32, i32* %11
%20 = load i32, i32* %10
%21 = call i64 @mat_to_arr(i32 %18, i32 %19, i32 %20)
%22 = getelementptr inbounds i32, i32* %17, i64 %21
%23 = load i32*, i32** %6
%24 = load i32, i32* %8
%25 = load i32, i32* %11
%26 = load i32, i32* %10
%27 = call i64 @mat_to_arr(i32 %24, i32 %25, i32 %26)
%28 = getelementptr inbounds i32, i32* %23, i64 %27
%29 = call i32 @swap_ints(i32* %22, i32* %28)
br label %30
30: ; preds = %16
%31 = load i32, i32* %11
%32 = add i32 %31, 1
store i32 %32, i32* %11
br label %12
33: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @swap_rows(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %4, 0
br i1 %6, label %7, label %8
7: ; preds = %8, %5
ret void
8: ; preds = %5, %8
%9 = phi i32 [ %15, %8 ], [ 1, %5 ]
%10 = tail call i64 @mat_to_arr(i32 %1, i32 %9, i32 %4)
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = tail call i64 @mat_to_arr(i32 %2, i32 %9, i32 %4)
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = tail call i32 @swap_ints(i32* %11, i32* %13)
%15 = add i32 %9, 1
%16 = icmp ugt i32 %15, %4
br i1 %16, label %7, label %8
}