#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*/ free(char *);
scalar_t__ malloc(long);
int /*<<< orphan*/ memcpy(char *, char *, long);
void textureHorizontalFlipInPlace(char *bufsrc, long rowsize, long numlines) {
  char *one_line = (char *)malloc(rowsize);
  long current_line = 0;
  unsigned long last_line_offset = (numlines - 1) * rowsize;
  unsigned long top_line_offset = 0;
  unsigned long bottom_line_offset = 0;
  for (; current_line < numlines; current_line++) {
    top_line_offset = current_line * rowsize;
    bottom_line_offset = last_line_offset - top_line_offset;
    memcpy(one_line, bufsrc + bottom_line_offset, rowsize);
    memcpy(bufsrc + bottom_line_offset, bufsrc + top_line_offset, rowsize);
    memcpy(bufsrc + top_line_offset, one_line, rowsize);
  }
  free(one_line);
}


x86 assembly (clang, -O0):
<textureHorizontalFlipInPlace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11f5 <textureHorizontalFlipInPlace+0xc5>
mov    -0x28(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117a <textureHorizontalFlipInPlace+0x4a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<textureHorizontalFlipInPlace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r13
mov    %rsi,%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
test   %r15,%r15
jle    11a6 <textureHorizontalFlipInPlace+0x76>
lea    -0x1(%r15),%rbx
imul   %r14,%rbx
add    %r13,%rbx
mov    %r14,%rbp
neg    %rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
add    %r14,%r13
add    %rbp,%rbx
add    $0xffffffffffffffff,%r15
jne    1170 <textureHorizontalFlipInPlace+0x40>
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 @textureHorizontalFlipInPlace(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%12 = load i64, i64* %5
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
store i64 0, i64* %8
%15 = load i64, i64* %6
%16 = sub nsw i64 %15, 1
%17 = load i64, i64* %5
%18 = mul nsw i64 %16, %17
store i64 %18, i64* %9
store i64 0, i64* %10
store i64 0, i64* %11
br label %19
19: ; preds = %50, %3
%20 = load i64, i64* %8
%21 = load i64, i64* %6
%22 = icmp slt i64 %20, %21
br i1 %22, label %23, label %53
23: ; preds = %19
%24 = load i64, i64* %8
%25 = load i64, i64* %5
%26 = mul nsw i64 %24, %25
store i64 %26, i64* %10
%27 = load i64, i64* %9
%28 = load i64, i64* %10
%29 = sub i64 %27, %28
store i64 %29, i64* %11
%30 = load i8*, i8** %7
%31 = load i8*, i8** %4
%32 = load i64, i64* %11
%33 = getelementptr inbounds i8, i8* %31, i64 %32
%34 = load i64, i64* %5
%35 = call i32 @memcpy(i8* %30, i8* %33, i64 %34)
%36 = load i8*, i8** %4
%37 = load i64, i64* %11
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = load i8*, i8** %4
%40 = load i64, i64* %10
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = load i64, i64* %5
%43 = call i32 @memcpy(i8* %38, i8* %41, i64 %42)
%44 = load i8*, i8** %4
%45 = load i64, i64* %10
%46 = getelementptr inbounds i8, i8* %44, i64 %45
%47 = load i8*, i8** %7
%48 = load i64, i64* %5
%49 = call i32 @memcpy(i8* %46, i8* %47, i64 %48)
br label %50
50: ; preds = %23
%51 = load i64, i64* %8
%52 = add nsw i64 %51, 1
store i64 %52, i64* %8
br label %19
53: ; preds = %19
%54 = load i8*, i8** %7
%55 = call i32 @free(i8* %54)
ret void
}

LLVM IR (-O2):
define void @textureHorizontalFlipInPlace(i8* %0, i64 %1, i64 %2) {
%4 = tail call i64 @malloc(i64 %1)
%5 = inttoptr i64 %4 to i8*
%6 = add nsw i64 %2, -1
%7 = mul nsw i64 %6, %1
%8 = icmp sgt i64 %2, 0
br i1 %8, label %9, label %20
9: ; preds = %3, %9
%10 = phi i64 [ %18, %9 ], [ 0, %3 ]
%11 = mul nsw i64 %10, %1
%12 = sub i64 %7, %11
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i32 @memcpy(i8* %5, i8* %13, i64 %1)
%15 = getelementptr inbounds i8, i8* %0, i64 %11
%16 = tail call i32 @memcpy(i8* %13, i8* %15, i64 %1)
%17 = tail call i32 @memcpy(i8* %15, i8* %5, i64 %1)
%18 = add nuw nsw i64 %10, 1
%19 = icmp eq i64 %18, %2
br i1 %19, label %20, label %9
20: ; preds = %9, %3
%21 = tail call i32 @free(i8* %5)
ret void
}