#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int conversion(FILE *input_file, FILE *output_file, int total_bytes,
               char method) {
  int i, count, average;
  unsigned char *dynamic_array = NULL;
  unsigned char *dynamic_proof = NULL;
  unsigned char char_array[3];
  dynamic_array = (unsigned char *)malloc(total_bytes * sizeof(unsigned char));
  dynamic_proof = (unsigned char *)malloc(1 * sizeof(unsigned char));
  count = fread(dynamic_array, sizeof(char), total_bytes, input_file);
  if (count <= 0)
    return 2;
  if (count != total_bytes)
    return 2;
  count = fread(dynamic_proof, sizeof(char), 1, input_file);
  if ((int)dynamic_proof[0] != 0)
    return 2;
  for (i = 0; i < total_bytes; i++) {
    if (method == 'l')
      average = ((int)dynamic_array[i] * 21 + (int)dynamic_array[i + 1] * 71 +
                 (int)dynamic_array[i + 2] * 8) /
                100;
    else
      average = ((int)dynamic_array[i] + (int)dynamic_array[i + 1] +
                 (int)dynamic_array[i + 2]) /
                3;
    char_array[0] = (unsigned char)average;
    char_array[1] = (unsigned char)average;
    char_array[2] = (unsigned char)average;
    fwrite(char_array, sizeof(unsigned char), 3, output_file);
    i += 2;
  }
  free(dynamic_array);
  free(dynamic_proof);
  return 0;
}


x86 assembly (clang, -O0):
<conversion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     11b7 <conversion+0x77>
movl   $0x2,-0x4(%rbp)
jmp    1303 <conversion+0x1c3>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11cf <conversion+0x8f>
movl   $0x2,-0x4(%rbp)
jmp    1303 <conversion+0x1c3>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     1202 <conversion+0xc2>
movl   $0x2,-0x4(%rbp)
jmp    1303 <conversion+0x1c3>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12ea <conversion+0x1aa>
movsbl -0x1d(%rbp),%eax
cmp    $0x6c,%eax
jne    126d <conversion+0x12d>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
imul   $0x15,%eax,%eax
mov    -0x38(%rbp),%rcx
mov    -0x24(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
imul   $0x47,%ecx,%ecx
add    %ecx,%eax
mov    -0x38(%rbp),%rcx
mov    -0x24(%rbp),%edx
add    $0x2,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
shl    $0x3,%ecx
add    %ecx,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
jmp    12aa <conversion+0x16a>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x38(%rbp),%rcx
mov    -0x24(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    -0x38(%rbp),%rcx
mov    -0x24(%rbp),%edx
add    $0x2,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %al,-0x43(%rbp)
mov    -0x2c(%rbp),%eax
mov    %al,-0x42(%rbp)
mov    -0x2c(%rbp),%eax
mov    %al,-0x41(%rbp)
lea    -0x43(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1060 <fwrite@plt>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1209 <conversion+0xc9>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conversion>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0xc(%rsp)
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r13
mov    %edx,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
mov    $0x2,%r12d
test   %eax,%eax
jle    126c <conversion+0x12c>
cmp    %r14d,%eax
jne    126c <conversion+0x12c>
mov    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
mov    %rdi,%rbp
call   1040 <fread@plt>
cmpb   $0x0,0x0(%rbp)
jne    126c <conversion+0x12c>
test   %r14d,%r14d
mov    0xc(%rsp),%r12d
jle    1257 <conversion+0x117>
xor    %ebp,%ebp
lea    0x9(%rsp),%r13
jmp    1224 <conversion+0xe4>
nopl   0x0(%rax)
movzbl 0x1(%rbx,%rbp,1),%ecx
movzwl %ax,%eax
add    %ecx,%eax
movzbl 0x2(%rbx,%rbp,1),%ecx
add    %eax,%ecx
imul   $0xaaab,%ecx,%eax
shr    $0x11,%eax
mov    %al,0x9(%rsp)
mov    %al,0xa(%rsp)
mov    %al,0xb(%rsp)
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
add    $0x3,%rbp
cmp    %r14d,%ebp
jge    1257 <conversion+0x117>
movzbl (%rbx,%rbp,1),%eax
cmp    $0x6c,%r12b
jne    11e0 <conversion+0xa0>
movzwl %ax,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rax,%rcx,4),%eax
movzbl 0x1(%rbx,%rbp,1),%ecx
imul   $0x47,%ecx,%ecx
add    %eax,%ecx
movzbl 0x2(%rbx,%rbp,1),%eax
lea    (%rcx,%rax,8),%eax
movzwl %ax,%eax
shr    $0x2,%eax
imul   $0x147b,%eax,%eax
jmp    11f7 <conversion+0xb7>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @conversion(i32* nocapture %0, i32* nocapture %1, i32 %2, i8 signext %3) {
%5 = alloca [3 x i8]
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%7 = tail call i64 @malloc(i32 %2)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 @malloc(i32 1)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @fread(i8* %8, i32 1, i32 %2, i32* %0)
%12 = icmp sgt i32 %11, 0
%13 = icmp eq i32 %11, %2
%14 = and i1 %12, %13
br i1 %14, label %15, label %67
15: ; preds = %4
%16 = tail call i32 @fread(i8* %10, i32 1, i32 1, i32* %0)
%17 = load i8, i8* %10
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %67
19: ; preds = %15
%20 = icmp sgt i32 %2, 0
br i1 %20, label %21, label %64
21: ; preds = %19
%22 = icmp eq i8 %3, 108
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
br label %25
25: ; preds = %21, %57
%26 = phi i64 [ 0, %21 ], [ %61, %57 ]
%27 = getelementptr inbounds i8, i8* %8, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i16
br i1 %22, label %30, label %45
30: ; preds = %25
%31 = mul nuw nsw i16 %29, 21
%32 = add nuw nsw i64 %26, 1
%33 = getelementptr inbounds i8, i8* %8, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i16
%36 = mul nuw nsw i16 %35, 71
%37 = add nuw nsw i16 %36, %31
%38 = add nuw nsw i64 %26, 2
%39 = getelementptr inbounds i8, i8* %8, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i16
%42 = shl nuw nsw i16 %41, 3
%43 = add nuw nsw i16 %37, %42
%44 = udiv i16 %43, 100
br label %57
45: ; preds = %25
%46 = add nuw nsw i64 %26, 1
%47 = getelementptr inbounds i8, i8* %8, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i16
%50 = add nuw nsw i16 %49, %29
%51 = add nuw nsw i64 %26, 2
%52 = getelementptr inbounds i8, i8* %8, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i16
%55 = add nuw nsw i16 %50, %54
%56 = udiv i16 %55, 3
br label %57
57: ; preds = %45, %30
%58 = phi i16 [ %44, %30 ], [ %56, %45 ]
%59 = trunc i16 %58 to i8
store i8 %59, i8* %6
store i8 %59, i8* %23
store i8 %59, i8* %24
%60 = call i32 @fwrite(i8* %6, i32 1, i32 3, i32* %1)
%61 = add nuw i64 %26, 3
%62 = trunc i64 %61 to i32
%63 = icmp slt i32 %62, %2
br i1 %63, label %25, label %64
64: ; preds = %57, %19
%65 = tail call i32 @free(i8* %8)
%66 = tail call i32 @free(i8* %10)
br label %67
67: ; preds = %15, %4, %64
%68 = phi i32 [ 0, %64 ], [ 2, %4 ], [ 2, %15 ]
ret i32 %68
}