#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*/ printf(char *);
int abgr8888_to_bgra8888(const void *psrc, int w, int h, void *pdst) {
  int srclinesize = (((w * 4) + 3) & ~3);
  int dstlinesize = (((w * 4) + 3) & ~3);
  const unsigned char *psrcline;
  const unsigned char *psrcdot;
  unsigned char *pdstline;
  unsigned char *pdstdot;
  int i, j;
  if (!psrc || !pdst || w <= 0 || h <= 0) {
    printf("abgr8888_to_bgra8888 : parameter error\n");
    return -1;
  }
  psrcline = (const unsigned char *)psrc;
  pdstline = (unsigned char *)pdst;
  for (i = 0; i < h; i++) {
    psrcdot = psrcline;
    pdstdot = pdstline;
    for (j = 0; j < w; j++) {
      pdstdot[0] = psrcdot[1];
      pdstdot[1] = psrcdot[2];
      pdstdot[2] = psrcdot[3];
      pdstdot[3] = psrcdot[0];
      psrcdot += 4;
      pdstdot += 4;
    }
    psrcline += srclinesize;
    pdstline += dstlinesize;
  }
  return 0;
}


x86 assembly (clang, -O0):
<abgr8888_to_bgra8888>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    $0x3,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    $0x3,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116e <abgr8888_to_bgra8888+0x5e>
cmpq   $0x0,-0x20(%rbp)
je     116e <abgr8888_to_bgra8888+0x5e>
cmpl   $0x0,-0x14(%rbp)
jle    116e <abgr8888_to_bgra8888+0x5e>
cmpl   $0x0,-0x18(%rbp)
jg     1186 <abgr8888_to_bgra8888+0x76>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125f <abgr8888_to_bgra8888+0x14f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1258 <abgr8888_to_bgra8888+0x148>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1228 <abgr8888_to_bgra8888+0x118>
mov    -0x38(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x48(%rbp),%rax
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x48(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x38(%rbp),%rax
mov    0x3(%rax),%cl
mov    -0x48(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%cl
mov    -0x48(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11c0 <abgr8888_to_bgra8888+0xb0>
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    119d <abgr8888_to_bgra8888+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abgr8888_to_bgra8888>:
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1208 <abgr8888_to_bgra8888+0xf8>
test   %esi,%esi
jle    1208 <abgr8888_to_bgra8888+0xf8>
test   %rdi,%rdi
je     1208 <abgr8888_to_bgra8888+0xf8>
test   %rcx,%rcx
je     1208 <abgr8888_to_bgra8888+0xf8>
lea    0x0(,%rsi,4),%eax
movslq %eax,%r8
mov    %esi,%r10d
and    $0xfffffffe,%r10d
xor    %r9d,%r9d
jmp    1163 <abgr8888_to_bgra8888+0x53>
nopl   0x0(%rax)
add    %r8,%rdi
add    %r8,%rcx
add    $0x1,%r9d
cmp    %edx,%r9d
je     121b <abgr8888_to_bgra8888+0x10b>
mov    %rcx,%r14
mov    %rdi,%rbx
cmp    $0x1,%esi
je     11df <abgr8888_to_bgra8888+0xcf>
xor    %eax,%eax
xor    %r11d,%r11d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%rdi,%rax,4),%ebx
mov    %bl,(%rcx,%rax,4)
movzbl 0x2(%rdi,%rax,4),%ebx
mov    %bl,0x1(%rcx,%rax,4)
movzbl 0x3(%rdi,%rax,4),%ebx
mov    %bl,0x2(%rcx,%rax,4)
movzbl (%rdi,%rax,4),%ebx
mov    %bl,0x3(%rcx,%rax,4)
movzbl 0x5(%rdi,%rax,4),%ebx
mov    %bl,0x4(%rcx,%rax,4)
movzbl 0x6(%rdi,%rax,4),%ebx
mov    %bl,0x5(%rcx,%rax,4)
movzbl 0x7(%rdi,%rax,4),%ebx
mov    %bl,0x6(%rcx,%rax,4)
movzbl 0x4(%rdi,%rax,4),%ebx
mov    %bl,0x7(%rcx,%rax,4)
add    $0xfffffffffffffff8,%r11
add    $0x2,%rax
cmp    %eax,%r10d
jne    1180 <abgr8888_to_bgra8888+0x70>
mov    %rcx,%r14
sub    %r11,%r14
mov    %rdi,%rbx
sub    %r11,%rbx
test   $0x1,%sil
je     1150 <abgr8888_to_bgra8888+0x40>
mov    0x1(%rbx),%al
mov    %al,(%r14)
mov    0x2(%rbx),%al
mov    %al,0x1(%r14)
mov    0x3(%rbx),%al
mov    %al,0x2(%r14)
mov    (%rbx),%al
mov    %al,0x3(%r14)
jmp    1150 <abgr8888_to_bgra8888+0x40>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    121d <abgr8888_to_bgra8888+0x10d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [40 x i8] c"abgr8888_to_bgra8888 : parameter error\0A\00"
define i32 @abgr8888_to_bgra8888(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%18 = load i32, i32* %7
%19 = mul nsw i32 %18, 4
%20 = add nsw i32 %19, 3
%21 = and i32 %20, -4
store i32 %21, i32* %10
%22 = load i32, i32* %7
%23 = mul nsw i32 %22, 4
%24 = add nsw i32 %23, 3
%25 = and i32 %24, -4
store i32 %25, i32* %11
%26 = load i8*, i8** %6
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %37
28: ; preds = %4
%29 = load i8*, i8** %9
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i32, i32* %7
%33 = icmp sle i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %8
%36 = icmp sle i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34, %31, %28, %4
%38 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %94
39: ; preds = %34
%40 = load i8*, i8** %6
store i8* %40, i8** %12
%41 = load i8*, i8** %9
store i8* %41, i8** %14
store i32 0, i32* %16
br label %42
42: ; preds = %90, %39
%43 = load i32, i32* %16
%44 = load i32, i32* %8
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %93
46: ; preds = %42
%47 = load i8*, i8** %12
store i8* %47, i8** %13
%48 = load i8*, i8** %14
store i8* %48, i8** %15
store i32 0, i32* %17
br label %49
49: ; preds = %78, %46
%50 = load i32, i32* %17
%51 = load i32, i32* %7
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %81
53: ; preds = %49
%54 = load i8*, i8** %13
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = load i8, i8* %55
%57 = load i8*, i8** %15
%58 = getelementptr inbounds i8, i8* %57, i64 0
store i8 %56, i8* %58
%59 = load i8*, i8** %13
%60 = getelementptr inbounds i8, i8* %59, i64 2
%61 = load i8, i8* %60
%62 = load i8*, i8** %15
%63 = getelementptr inbounds i8, i8* %62, i64 1
store i8 %61, i8* %63
%64 = load i8*, i8** %13
%65 = getelementptr inbounds i8, i8* %64, i64 3
%66 = load i8, i8* %65
%67 = load i8*, i8** %15
%68 = getelementptr inbounds i8, i8* %67, i64 2
store i8 %66, i8* %68
%69 = load i8*, i8** %13
%70 = getelementptr inbounds i8, i8* %69, i64 0
%71 = load i8, i8* %70
%72 = load i8*, i8** %15
%73 = getelementptr inbounds i8, i8* %72, i64 3
store i8 %71, i8* %73
%74 = load i8*, i8** %13
%75 = getelementptr inbounds i8, i8* %74, i64 4
store i8* %75, i8** %13
%76 = load i8*, i8** %15
%77 = getelementptr inbounds i8, i8* %76, i64 4
store i8* %77, i8** %15
br label %78
78: ; preds = %53
%79 = load i32, i32* %17
%80 = add nsw i32 %79, 1
store i32 %80, i32* %17
br label %49
81: ; preds = %49
%82 = load i32, i32* %10
%83 = load i8*, i8** %12
%84 = sext i32 %82 to i64
%85 = getelementptr inbounds i8, i8* %83, i64 %84
store i8* %85, i8** %12
%86 = load i32, i32* %11
%87 = load i8*, i8** %14
%88 = sext i32 %86 to i64
%89 = getelementptr inbounds i8, i8* %87, i64 %88
store i8* %89, i8** %14
br label %90
90: ; preds = %81
%91 = load i32, i32* %16
%92 = add nsw i32 %91, 1
store i32 %92, i32* %16
br label %42
93: ; preds = %42
store i32 0, i32* %5
br label %94
94: ; preds = %93, %37
%95 = load i32, i32* %5
ret i32 %95
}

LLVM IR (-O2):
@str = [39 x i8] c"abgr8888_to_bgra8888 : parameter error\00"
define i32 @abgr8888_to_bgra8888(i8* %0, i32 %1, i32 %2, i8* writeonly %3) {
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %3, null
%7 = or i1 %5, %6
%8 = icmp slt i32 %1, 1
%9 = or i1 %8, %7
%10 = icmp slt i32 %2, 1
%11 = or i1 %10, %9
br i1 %11, label %19, label %12
12: ; preds = %4
%13 = shl nsw i32 %1, 2
%14 = sext i32 %13 to i64
%15 = and i32 %1, 1
%16 = icmp eq i32 %1, 1
%17 = and i32 %1, -2
%18 = icmp eq i32 %15, 0
br label %21
19: ; preds = %4
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %74
21: ; preds = %12, %69
%22 = phi i32 [ 0, %12 ], [ %72, %69 ]
%23 = phi i8* [ %3, %12 ], [ %71, %69 ]
%24 = phi i8* [ %0, %12 ], [ %70, %69 ]
br i1 %16, label %55, label %25
25: ; preds = %21, %25
%26 = phi i8* [ %52, %25 ], [ %23, %21 ]
%27 = phi i8* [ %51, %25 ], [ %24, %21 ]
%28 = phi i32 [ %53, %25 ], [ 0, %21 ]
%29 = getelementptr inbounds i8, i8* %27, i64 1
%30 = load i8, i8* %29
store i8 %30, i8* %26
%31 = getelementptr inbounds i8, i8* %27, i64 2
%32 = load i8, i8* %31
%33 = getelementptr inbounds i8, i8* %26, i64 1
store i8 %32, i8* %33
%34 = getelementptr inbounds i8, i8* %27, i64 3
%35 = load i8, i8* %34
%36 = getelementptr inbounds i8, i8* %26, i64 2
store i8 %35, i8* %36
%37 = load i8, i8* %27
%38 = getelementptr inbounds i8, i8* %26, i64 3
store i8 %37, i8* %38
%39 = getelementptr inbounds i8, i8* %27, i64 4
%40 = getelementptr inbounds i8, i8* %26, i64 4
%41 = getelementptr inbounds i8, i8* %27, i64 5
%42 = load i8, i8* %41
store i8 %42, i8* %40
%43 = getelementptr inbounds i8, i8* %27, i64 6
%44 = load i8, i8* %43
%45 = getelementptr inbounds i8, i8* %26, i64 5
store i8 %44, i8* %45
%46 = getelementptr inbounds i8, i8* %27, i64 7
%47 = load i8, i8* %46
%48 = getelementptr inbounds i8, i8* %26, i64 6
store i8 %47, i8* %48
%49 = load i8, i8* %39
%50 = getelementptr inbounds i8, i8* %26, i64 7
store i8 %49, i8* %50
%51 = getelementptr inbounds i8, i8* %27, i64 8
%52 = getelementptr inbounds i8, i8* %26, i64 8
%53 = add i32 %28, 2
%54 = icmp eq i32 %53, %17
br i1 %54, label %55, label %25
55: ; preds = %25, %21
%56 = phi i8* [ %23, %21 ], [ %52, %25 ]
%57 = phi i8* [ %24, %21 ], [ %51, %25 ]
br i1 %18, label %69, label %58
58: ; preds = %55
%59 = getelementptr inbounds i8, i8* %57, i64 1
%60 = load i8, i8* %59
store i8 %60, i8* %56
%61 = getelementptr inbounds i8, i8* %57, i64 2
%62 = load i8, i8* %61
%63 = getelementptr inbounds i8, i8* %56, i64 1
store i8 %62, i8* %63
%64 = getelementptr inbounds i8, i8* %57, i64 3
%65 = load i8, i8* %64
%66 = getelementptr inbounds i8, i8* %56, i64 2
store i8 %65, i8* %66
%67 = load i8, i8* %57
%68 = getelementptr inbounds i8, i8* %56, i64 3
store i8 %67, i8* %68
br label %69
69: ; preds = %55, %58
%70 = getelementptr inbounds i8, i8* %24, i64 %14
%71 = getelementptr inbounds i8, i8* %23, i64 %14
%72 = add nuw nsw i32 %22, 1
%73 = icmp eq i32 %72, %2
br i1 %73, label %74, label %21
74: ; preds = %69, %19
%75 = phi i32 [ -1, %19 ], [ 0, %69 ]
ret i32 %75
}