#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*/ assert(int);
int /*<<< orphan*/ free(unsigned char *const);
scalar_t__ malloc(size_t const);
int /*<<< orphan*/ memcpy(unsigned char *const, unsigned char *const,
                          size_t const);
void flipVertically(unsigned char *const inOutPixels, int const inWidth,
                    int const inHeight) {
  assert(inOutPixels != NULL);
  assert(inWidth > 0);
  assert(inHeight > 0);
  size_t const rowByteWidth = inWidth * 3 * sizeof(unsigned char);
  unsigned char *const rowBuf = (unsigned char *)malloc(rowByteWidth);
  for (int row = 0; row < inHeight / 2; ++row) {
    unsigned char *const rowPtr = inOutPixels + row * rowByteWidth,
                         *const otherRowPtr =
                             inOutPixels + (inHeight - 1 - row) * rowByteWidth;
    memcpy(rowBuf, otherRowPtr, rowByteWidth);
    memcpy(otherRowPtr, rowPtr, rowByteWidth);
    memcpy(rowPtr, rowBuf, rowByteWidth);
  }
  free(rowBuf);
}


x86 assembly (clang, -O0):
<flipVertically>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x10(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
imul   $0x3,-0xc(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jge    1237 <flipVertically+0xf7>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x24(%rbp),%ecx
movslq %ecx,%rcx
imul   -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a8 <flipVertically+0x68>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flipVertically>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %esi,%ebx
mov    %rdi,%rax
xor    %edi,%edi
mov    %rax,(%rsp)
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %ebx,%ebx
setg   %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r13d,%r13d
setg   %dil
call   1040 <assert@plt>
lea    (%rbx,%rbx,2),%eax
movslq %eax,%r15
mov    %r15,%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
cmp    $0x2,%r13d
jl     11f5 <flipVertically+0xb5>
mov    %r13d,%r14d
shr    %r14d
add    $0xffffffff,%r13d
mov    (%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movslq %r13d,%r13
mov    %r13,%rbp
imul   %r15,%rbp
add    (%rsp),%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
add    $0xffffffff,%r13d
add    %r15,%rbx
add    $0xffffffffffffffff,%r14
jne    11b0 <flipVertically+0x70>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @flipVertically(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* %6
%21 = icmp sgt i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32, i32* %5
%25 = mul nsw i32 %24, 3
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
store i64 %27, i64* %7
%28 = load i64, i64* %7
%29 = call i64 @malloc(i64 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %8
store i32 0, i32* %9
br label %31
31: ; preds = %64, %3
%32 = load i32, i32* %9
%33 = load i32, i32* %6
%34 = sdiv i32 %33, 2
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %67
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = load i64, i64* %7
%41 = mul i64 %39, %40
%42 = getelementptr inbounds i8, i8* %37, i64 %41
store i8* %42, i8** %10
%43 = load i8*, i8** %4
%44 = load i32, i32* %6
%45 = sub nsw i32 %44, 1
%46 = load i32, i32* %9
%47 = sub nsw i32 %45, %46
%48 = sext i32 %47 to i64
%49 = load i64, i64* %7
%50 = mul i64 %48, %49
%51 = getelementptr inbounds i8, i8* %43, i64 %50
store i8* %51, i8** %11
%52 = load i8*, i8** %8
%53 = load i8*, i8** %11
%54 = load i64, i64* %7
%55 = call i32 @memcpy(i8* %52, i8* %53, i64 %54)
%56 = load i8*, i8** %11
%57 = load i8*, i8** %10
%58 = load i64, i64* %7
%59 = call i32 @memcpy(i8* %56, i8* %57, i64 %58)
%60 = load i8*, i8** %10
%61 = load i8*, i8** %8
%62 = load i64, i64* %7
%63 = call i32 @memcpy(i8* %60, i8* %61, i64 %62)
br label %64
64: ; preds = %36
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %31
67: ; preds = %31
%68 = load i8*, i8** %8
%69 = call i32 @free(i8* %68)
ret void
}

LLVM IR (-O2):
define void @flipVertically(i8* %0, i32 %1, i32 %2) {
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp sgt i32 %1, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp sgt i32 %2, 0
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = mul nsw i32 %1, 3
%14 = sext i32 %13 to i64
%15 = tail call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
%17 = icmp sgt i32 %2, 1
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = lshr i32 %2, 1
%20 = zext i32 %19 to i64
br label %23
21: ; preds = %23, %3
%22 = tail call i32 @free(i8* %16)
ret void
23: ; preds = %18, %23
%24 = phi i64 [ 0, %18 ], [ %36, %23 ]
%25 = mul nsw i64 %24, %14
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = trunc i64 %24 to i32
%28 = xor i32 %27, -1
%29 = add i32 %28, %2
%30 = sext i32 %29 to i64
%31 = mul nsw i64 %30, %14
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = tail call i32 @memcpy(i8* %16, i8* %32, i64 %14)
%34 = tail call i32 @memcpy(i8* %32, i8* %26, i64 %14)
%35 = tail call i32 @memcpy(i8* %26, i8* %16, i64 %14)
%36 = add nuw nsw i64 %24, 1
%37 = icmp eq i64 %36, %20
br i1 %37, label %21, label %23
}