#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 */
scalar_t__ malloc(int);
unsigned char test() {
  int i, Pels;
  int sum = 0;
  unsigned char xr, xg, xb;
  unsigned char xc, xm, xy, xk = 0;
  unsigned char *ReadPtr, *EritePtr;
  ReadPtr = (unsigned char *)malloc(sizeof(unsigned char) * 100);
  EritePtr = (unsigned char *)malloc(sizeof(unsigned char) * 100);
  for (i = 0; i < 100; i++) {
    ReadPtr[i] = 100 - i;
  }
  for (i = 0; i < 24; i++) {
    xr = *ReadPtr++;
    xg = *ReadPtr++;
    xb = *ReadPtr++;
    xc = (unsigned char)(255 - xr);
    xm = (unsigned char)(255 - xg);
    xy = (unsigned char)(255 - xb);
    if (xc < xm) {
      xk = (unsigned char)(xc < xy ? xc : xy);
    } else {
      xk = (unsigned char)(xm < xy ? xm : xy);
    }
    xc = (unsigned char)(xc - xk);
    xm = (unsigned char)(xm - xk);
    xy = (unsigned char)(xy - xk);
    *EritePtr++ = xc;
    *EritePtr++ = xm;
    *EritePtr++ = xy;
    *EritePtr++ = xk;
    sum += *(--EritePtr);
  }
  return sum;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0x13(%rbp)
mov    $0x64,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x64,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x64,-0x4(%rbp)
jge    1173 <test+0x63>
mov    $0x64,%eax
sub    -0x4(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1146 <test+0x36>
movl   $0x0,-0x4(%rbp)
cmpl   $0x18,-0x4(%rbp)
jge    12ef <test+0x1df>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0xd(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0xe(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0xf(%rbp)
movzbl -0xd(%rbp),%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,-0x10(%rbp)
movzbl -0xe(%rbp),%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,-0x11(%rbp)
movzbl -0xf(%rbp),%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,-0x12(%rbp)
movzbl -0x10(%rbp),%eax
movzbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jge    1228 <test+0x118>
movzbl -0x10(%rbp),%eax
movzbl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jge    1216 <test+0x106>
movzbl -0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    121d <test+0x10d>
movzbl -0x12(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %al,-0x13(%rbp)
jmp    1251 <test+0x141>
movzbl -0x11(%rbp),%eax
movzbl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jge    1244 <test+0x134>
movzbl -0x11(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    124b <test+0x13b>
movzbl -0x12(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %al,-0x13(%rbp)
movzbl -0x10(%rbp),%eax
movzbl -0x13(%rbp),%ecx
sub    %ecx,%eax
mov    %al,-0x10(%rbp)
movzbl -0x11(%rbp),%eax
movzbl -0x13(%rbp),%ecx
sub    %ecx,%eax
mov    %al,-0x11(%rbp)
movzbl -0x12(%rbp),%eax
movzbl -0x13(%rbp),%ecx
sub    %ecx,%eax
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x11(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x12(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x13(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movzbl -0x1(%rax),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    117a <test+0x6a>
mov    -0xc(%rbp),%eax
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %r14
push   %rbx
push   %rax
mov    $0x64,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    $0x64,%edi
call   1030 <malloc@plt>
movaps 0xece(%rip),%xmm0
movups %xmm0,(%r14)
movaps 0xed3(%rip),%xmm0
movups %xmm0,0x10(%r14)
movaps 0xed7(%rip),%xmm0
movups %xmm0,0x20(%r14)
movaps 0xedb(%rip),%xmm0
movups %xmm0,0x30(%r14)
movaps 0xedf(%rip),%xmm0
movups %xmm0,0x40(%r14)
movaps 0xee3(%rip),%xmm0
movups %xmm0,0x50(%r14)
movl   $0x1020304,0x60(%r14)
01
xor    %edx,%edx
xor    %r8d,%r8d
nop
movzbl (%r14,%rdx,1),%r9d
movzbl 0x1(%r14,%rdx,1),%edi
movzbl 0x2(%r14,%rdx,1),%esi
cmp    %sil,%r9b
mov    %esi,%ebx
cmova  %r9d,%ebx
cmp    %dil,%bl
cmovbe %edi,%ebx
mov    %ebx,%ecx
not    %cl
mov    %ebx,%r10d
sub    %r9b,%r10b
mov    %ebx,%r9d
sub    %dil,%r9b
sub    %sil,%bl
mov    %r10b,(%rax,%rdx,1)
mov    %r9b,0x1(%rax,%rdx,1)
mov    %bl,0x2(%rax,%rdx,1)
mov    %cl,0x3(%rax,%rdx,1)
movzbl %cl,%ecx
add    %ecx,%r8d
add    $0x3,%rdx
cmp    $0x48,%edx
jne    1180 <test+0x70>
mov    %r8d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define zeroext i8 @test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %3
store i8 0, i8* %10
%13 = call i64 @malloc(i32 100)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %11
%15 = call i64 @malloc(i32 100)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %12
store i32 0, i32* %1
br label %17
17: ; preds = %28, %0
%18 = load i32, i32* %1
%19 = icmp slt i32 %18, 100
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = load i32, i32* %1
%22 = sub nsw i32 100, %21
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %11
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
br label %28
28: ; preds = %20
%29 = load i32, i32* %1
%30 = add nsw i32 %29, 1
store i32 %30, i32* %1
br label %17
31: ; preds = %17
store i32 0, i32* %1
br label %32
32: ; preds = %129, %31
%33 = load i32, i32* %1
%34 = icmp slt i32 %33, 24
br i1 %34, label %35, label %132
35: ; preds = %32
%36 = load i8*, i8** %11
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %11
%38 = load i8, i8* %36
store i8 %38, i8* %4
%39 = load i8*, i8** %11
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %11
%41 = load i8, i8* %39
store i8 %41, i8* %5
%42 = load i8*, i8** %11
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %11
%44 = load i8, i8* %42
store i8 %44, i8* %6
%45 = load i8, i8* %4
%46 = zext i8 %45 to i32
%47 = sub nsw i32 255, %46
%48 = trunc i32 %47 to i8
store i8 %48, i8* %7
%49 = load i8, i8* %5
%50 = zext i8 %49 to i32
%51 = sub nsw i32 255, %50
%52 = trunc i32 %51 to i8
store i8 %52, i8* %8
%53 = load i8, i8* %6
%54 = zext i8 %53 to i32
%55 = sub nsw i32 255, %54
%56 = trunc i32 %55 to i8
store i8 %56, i8* %9
%57 = load i8, i8* %7
%58 = zext i8 %57 to i32
%59 = load i8, i8* %8
%60 = zext i8 %59 to i32
%61 = icmp slt i32 %58, %60
br i1 %61, label %62, label %77
62: ; preds = %35
%63 = load i8, i8* %7
%64 = zext i8 %63 to i32
%65 = load i8, i8* %9
%66 = zext i8 %65 to i32
%67 = icmp slt i32 %64, %66
br i1 %67, label %68, label %71
68: ; preds = %62
%69 = load i8, i8* %7
%70 = zext i8 %69 to i32
br label %74
71: ; preds = %62
%72 = load i8, i8* %9
%73 = zext i8 %72 to i32
br label %74
74: ; preds = %71, %68
%75 = phi i32 [ %70, %68 ], [ %73, %71 ]
%76 = trunc i32 %75 to i8
store i8 %76, i8* %10
br label %92
77: ; preds = %35
%78 = load i8, i8* %8
%79 = zext i8 %78 to i32
%80 = load i8, i8* %9
%81 = zext i8 %80 to i32
%82 = icmp slt i32 %79, %81
br i1 %82, label %83, label %86
83: ; preds = %77
%84 = load i8, i8* %8
%85 = zext i8 %84 to i32
br label %89
86: ; preds = %77
%87 = load i8, i8* %9
%88 = zext i8 %87 to i32
br label %89
89: ; preds = %86, %83
%90 = phi i32 [ %85, %83 ], [ %88, %86 ]
%91 = trunc i32 %90 to i8
store i8 %91, i8* %10
br label %92
92: ; preds = %89, %74
%93 = load i8, i8* %7
%94 = zext i8 %93 to i32
%95 = load i8, i8* %10
%96 = zext i8 %95 to i32
%97 = sub nsw i32 %94, %96
%98 = trunc i32 %97 to i8
store i8 %98, i8* %7
%99 = load i8, i8* %8
%100 = zext i8 %99 to i32
%101 = load i8, i8* %10
%102 = zext i8 %101 to i32
%103 = sub nsw i32 %100, %102
%104 = trunc i32 %103 to i8
store i8 %104, i8* %8
%105 = load i8, i8* %9
%106 = zext i8 %105 to i32
%107 = load i8, i8* %10
%108 = zext i8 %107 to i32
%109 = sub nsw i32 %106, %108
%110 = trunc i32 %109 to i8
store i8 %110, i8* %9
%111 = load i8, i8* %7
%112 = load i8*, i8** %12
%113 = getelementptr inbounds i8, i8* %112, i32 1
store i8* %113, i8** %12
store i8 %111, i8* %112
%114 = load i8, i8* %8
%115 = load i8*, i8** %12
%116 = getelementptr inbounds i8, i8* %115, i32 1
store i8* %116, i8** %12
store i8 %114, i8* %115
%117 = load i8, i8* %9
%118 = load i8*, i8** %12
%119 = getelementptr inbounds i8, i8* %118, i32 1
store i8* %119, i8** %12
store i8 %117, i8* %118
%120 = load i8, i8* %10
%121 = load i8*, i8** %12
%122 = getelementptr inbounds i8, i8* %121, i32 1
store i8* %122, i8** %12
store i8 %120, i8* %121
%123 = load i8*, i8** %12
%124 = getelementptr inbounds i8, i8* %123, i32 -1
store i8* %124, i8** %12
%125 = load i8, i8* %124
%126 = zext i8 %125 to i32
%127 = load i32, i32* %3
%128 = add nsw i32 %127, %126
store i32 %128, i32* %3
br label %129
129: ; preds = %92
%130 = load i32, i32* %1
%131 = add nsw i32 %130, 1
store i32 %131, i32* %1
br label %32
132: ; preds = %32
%133 = load i32, i32* %3
%134 = trunc i32 %133 to i8
ret i8 %134
}

LLVM IR (-O2):
define zeroext i8 @test() {
%1 = tail call i64 @malloc(i32 100)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i64 @malloc(i32 100)
%4 = inttoptr i64 %1 to <16 x i8>*
store <16 x i8> <i8 100, i8 99, i8 98, i8 97, i8 96, i8 95, i8 94, i8 93, i8 92, i8 91, i8 90, i8 89, i8 88, i8 87, i8 86, i8 85>, <16 x i8>* %4
%5 = getelementptr inbounds i8, i8* %2, i64 16
%6 = bitcast i8* %5 to <16 x i8>*
store <16 x i8> <i8 84, i8 83, i8 82, i8 81, i8 80, i8 79, i8 78, i8 77, i8 76, i8 75, i8 74, i8 73, i8 72, i8 71, i8 70, i8 69>, <16 x i8>* %6
%7 = getelementptr inbounds i8, i8* %2, i64 32
%8 = bitcast i8* %7 to <16 x i8>*
store <16 x i8> <i8 68, i8 67, i8 66, i8 65, i8 64, i8 63, i8 62, i8 61, i8 60, i8 59, i8 58, i8 57, i8 56, i8 55, i8 54, i8 53>, <16 x i8>* %8
%9 = getelementptr inbounds i8, i8* %2, i64 48
%10 = bitcast i8* %9 to <16 x i8>*
store <16 x i8> <i8 52, i8 51, i8 50, i8 49, i8 48, i8 47, i8 46, i8 45, i8 44, i8 43, i8 42, i8 41, i8 40, i8 39, i8 38, i8 37>, <16 x i8>* %10
%11 = getelementptr inbounds i8, i8* %2, i64 64
%12 = bitcast i8* %11 to <16 x i8>*
store <16 x i8> <i8 36, i8 35, i8 34, i8 33, i8 32, i8 31, i8 30, i8 29, i8 28, i8 27, i8 26, i8 25, i8 24, i8 23, i8 22, i8 21>, <16 x i8>* %12
%13 = getelementptr inbounds i8, i8* %2, i64 80
%14 = bitcast i8* %13 to <16 x i8>*
store <16 x i8> <i8 20, i8 19, i8 18, i8 17, i8 16, i8 15, i8 14, i8 13, i8 12, i8 11, i8 10, i8 9, i8 8, i8 7, i8 6, i8 5>, <16 x i8>* %14
%15 = getelementptr inbounds i8, i8* %2, i64 96
store i8 4, i8* %15
%16 = getelementptr inbounds i8, i8* %2, i64 97
store i8 3, i8* %16
%17 = getelementptr inbounds i8, i8* %2, i64 98
store i8 2, i8* %17
%18 = getelementptr inbounds i8, i8* %2, i64 99
store i8 1, i8* %18
%19 = inttoptr i64 %3 to i8*
br label %20
20: ; preds = %0, %20
%21 = phi i8* [ %41, %20 ], [ %19, %0 ]
%22 = phi i8* [ %29, %20 ], [ %2, %0 ]
%23 = phi i32 [ %44, %20 ], [ 0, %0 ]
%24 = phi i32 [ %43, %20 ], [ 0, %0 ]
%25 = getelementptr inbounds i8, i8* %22, i64 1
%26 = load i8, i8* %22
%27 = getelementptr inbounds i8, i8* %22, i64 2
%28 = load i8, i8* %25
%29 = getelementptr inbounds i8, i8* %22, i64 3
%30 = load i8, i8* %27
%31 = icmp ugt i8 %26, %30
%32 = select i1 %31, i8 %26, i8 %30
%33 = icmp ugt i8 %32, %28
%34 = select i1 %33, i8 %32, i8 %28
%35 = xor i8 %34, -1
%36 = sub i8 %34, %26
%37 = sub i8 %34, %28
%38 = sub i8 %34, %30
%39 = getelementptr inbounds i8, i8* %21, i64 1
store i8 %36, i8* %21
%40 = getelementptr inbounds i8, i8* %21, i64 2
store i8 %37, i8* %39
%41 = getelementptr inbounds i8, i8* %21, i64 3
store i8 %38, i8* %40
store i8 %35, i8* %41
%42 = zext i8 %35 to i32
%43 = add nuw nsw i32 %24, %42
%44 = add nuw nsw i32 %23, 1
%45 = icmp eq i32 %44, 24
br i1 %45, label %46, label %20
46: ; preds = %20
%47 = trunc i32 %43 to i8
ret i8 %47
}