#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(void *);
void *malloc(size_t const);
void *memcpy(unsigned char *, void *, size_t const);
int /*<<< orphan*/ my_err(char *, char *, int);
void util_reverse(void *base, const size_t nmemb, const size_t size) {
  void *tmp;
  unsigned char *fwd_ptr, *rev_ptr;
  tmp = malloc(size);
  if (tmp == NULL) {
    my_err("%s:%d: could not allocate mem",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "util.c",
           760);
  }
  fwd_ptr = (unsigned char *)base;
  rev_ptr = &((unsigned char *)base)[nmemb * size - size];
  while (fwd_ptr < rev_ptr) {
    tmp = memcpy(tmp, fwd_ptr, size);
    memcpy(fwd_ptr, rev_ptr, size);
    memcpy(rev_ptr, tmp, size);
    fwd_ptr += size;
    rev_ptr -= size;
  }
  free(tmp);
}


x86 assembly (clang, -O0):
<util_reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1184 <util_reverse+0x44>
lea    0xe8d(%rip),%rdi
lea    0xea4(%rip),%rsi
mov    $0x2f8,%edx
call   1060 <my_err@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
imul   -0x18(%rbp),%rcx
sub    -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    120e <util_reverse+0xce>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    11a4 <util_reverse+0x64>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_reverse>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rdx,%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    117a <util_reverse+0x3a>
lea    0xe97(%rip),%rdi
lea    0xeae(%rip),%rsi
mov    $0x2f8,%edx
call   1060 <my_err@plt>
imul   %r14,%rbx
sub    %r14,%rbx
test   %rbx,%rbx
jle    11c5 <util_reverse+0x85>
add    %r15,%rbx
mov    %r14,%r13
neg    %r13
nop
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
add    %r14,%r15
add    %r13,%rbx
cmp    %rbx,%r15
jb     1190 <util_reverse+0x50>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"%s:%d: could not allocate mem\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
define void @util_reverse(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%10 = load i64, i64* %6
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @my_err(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 760)
br label %16
16: ; preds = %14, %3
%17 = load i8*, i8** %4
store i8* %17, i8** %8
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = load i64, i64* %6
%21 = mul i64 %19, %20
%22 = load i64, i64* %6
%23 = sub i64 %21, %22
%24 = getelementptr inbounds i8, i8* %18, i64 %23
store i8* %24, i8** %9
br label %25
25: ; preds = %29, %16
%26 = load i8*, i8** %8
%27 = load i8*, i8** %9
%28 = icmp ult i8* %26, %27
br i1 %28, label %29, label %49
29: ; preds = %25
%30 = load i8*, i8** %7
%31 = load i8*, i8** %8
%32 = load i64, i64* %6
%33 = call i8* @memcpy(i8* %30, i8* %31, i64 %32)
store i8* %33, i8** %7
%34 = load i8*, i8** %8
%35 = load i8*, i8** %9
%36 = load i64, i64* %6
%37 = call i8* @memcpy(i8* %34, i8* %35, i64 %36)
%38 = load i8*, i8** %9
%39 = load i8*, i8** %7
%40 = load i64, i64* %6
%41 = call i8* @memcpy(i8* %38, i8* %39, i64 %40)
%42 = load i64, i64* %6
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i64 %42
store i8* %44, i8** %8
%45 = load i64, i64* %6
%46 = load i8*, i8** %9
%47 = sub i64 0, %45
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %9
br label %25
49: ; preds = %25
%50 = load i8*, i8** %7
%51 = call i32 @free(i8* %50)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"%s:%d: could not allocate mem\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
define void @util_reverse(i8* %0, i64 %1, i64 %2) {
%4 = tail call i8* @malloc(i64 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @my_err(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 760)
br label %8
8: ; preds = %6, %3
%9 = mul i64 %2, %1
%10 = sub i64 %9, %2
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %0, i64 %10
%14 = sub i64 0, %2
br label %15
15: ; preds = %12, %15
%16 = phi i8* [ %13, %12 ], [ %19, %15 ]
%17 = phi i8* [ %0, %12 ], [ %18, %15 ]
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %4, i8* align 1 %17, i64 %2, i1 false)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %17, i8* align 1 %16, i64 %2, i1 false)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %16, i8* align 1 %4, i64 %2, i1 false)
%18 = getelementptr inbounds i8, i8* %17, i64 %2
%19 = getelementptr inbounds i8, i8* %16, i64 %14
%20 = icmp ult i8* %18, %19
br i1 %20, label %15, label %21
21: ; preds = %15, %8
%22 = tail call i32 @free(i8* %4)
ret void
}