#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(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int check_luminance(FILE *input_file, FILE *output_file) {
  int i, count;
  char *dynamic_array = NULL;
  dynamic_array = (char *)malloc(1 * sizeof(char));
  for (i = 0; i <= 3; i++) {
    count = fread(dynamic_array, sizeof(char), 1, input_file);
    if (count <= 0)
      return 4;
    if (i == 0) {
      if (dynamic_array[0] != '2') {
        free(dynamic_array);
        return 4;
      }
      fwrite(dynamic_array, sizeof(char), 1, output_file);
    }
    if (i == 1 || i == 2) {
      if (dynamic_array[0] != '5') {
        free(dynamic_array);
        return 4;
      }
      fwrite(dynamic_array, sizeof(char), 1, output_file);
    }
    if (i == 3) {
      if ((int)dynamic_array[0] != 10) {
        free(dynamic_array);
        return 4;
      }
      fwrite(dynamic_array, sizeof(char), 1, output_file);
    }
  }
  free(dynamic_array);
  return 0;
}


x86 assembly (clang, -O0):
<check_luminance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jg     128a <check_luminance+0x14a>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     11a4 <check_luminance+0x64>
movl   $0x4,-0x4(%rbp)
jmp    129a <check_luminance+0x15a>
cmpl   $0x0,-0x1c(%rbp)
jne    11e7 <check_luminance+0xa7>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x32,%eax
je     11d3 <check_luminance+0x93>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x4,-0x4(%rbp)
jmp    129a <check_luminance+0x15a>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <fwrite@plt>
cmpl   $0x1,-0x1c(%rbp)
je     11fb <check_luminance+0xbb>
cmpl   $0x2,-0x1c(%rbp)
jne    1234 <check_luminance+0xf4>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x35,%eax
je     1220 <check_luminance+0xe0>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x4,-0x4(%rbp)
jmp    129a <check_luminance+0x15a>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <fwrite@plt>
cmpl   $0x3,-0x1c(%rbp)
jne    1277 <check_luminance+0x137>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1263 <check_luminance+0x123>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x4,-0x4(%rbp)
jmp    129a <check_luminance+0x15a>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <fwrite@plt>
jmp    127c <check_luminance+0x13c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <check_luminance+0x2d>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_luminance>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    $0x4,%ebp
test   %eax,%eax
jle    122c <check_luminance+0xec>
cmpb   $0x32,(%rbx)
jne    1224 <check_luminance+0xe4>
mov    $0x32,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    $0x4,%ebp
test   %eax,%eax
jle    122c <check_luminance+0xec>
cmpb   $0x35,(%rbx)
jne    1224 <check_luminance+0xe4>
mov    $0x35,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    $0x4,%ebp
test   %eax,%eax
jle    122c <check_luminance+0xec>
cmpb   $0x35,(%rbx)
jne    1224 <check_luminance+0xe4>
mov    $0x35,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    $0x4,%ebp
test   %eax,%eax
jle    122c <check_luminance+0xec>
cmpb   $0xa,(%rbx)
jne    1224 <check_luminance+0xe4>
mov    $0xa,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_luminance(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* null, i8** %8
%9 = call i64 @malloc(i32 1)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %8
store i32 0, i32* %6
br label %11
11: ; preds = %73, %2
%12 = load i32, i32* %6
%13 = icmp sle i32 %12, 3
br i1 %13, label %14, label %76
14: ; preds = %11
%15 = load i8*, i8** %8
%16 = load i32*, i32** %4
%17 = call i32 @fread(i8* %15, i32 1, i32 1, i32* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 4, i32* %3
br label %79
21: ; preds = %14
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %21
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 50
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i8*, i8** %8
%32 = call i32 @free(i8* %31)
store i32 4, i32* %3
br label %79
33: ; preds = %24
%34 = load i8*, i8** %8
%35 = load i32*, i32** %5
%36 = call i32 @fwrite(i8* %34, i32 1, i32 1, i32* %35)
br label %37
37: ; preds = %33, %21
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, 1
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, 2
br i1 %42, label %43, label %56
43: ; preds = %40, %37
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i64 0
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 53
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = load i8*, i8** %8
%51 = call i32 @free(i8* %50)
store i32 4, i32* %3
br label %79
52: ; preds = %43
%53 = load i8*, i8** %8
%54 = load i32*, i32** %5
%55 = call i32 @fwrite(i8* %53, i32 1, i32 1, i32* %54)
br label %56
56: ; preds = %52, %40
%57 = load i32, i32* %6
%58 = icmp eq i32 %57, 3
br i1 %58, label %59, label %72
59: ; preds = %56
%60 = load i8*, i8** %8
%61 = getelementptr inbounds i8, i8* %60, i64 0
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp ne i32 %63, 10
br i1 %64, label %65, label %68
65: ; preds = %59
%66 = load i8*, i8** %8
%67 = call i32 @free(i8* %66)
store i32 4, i32* %3
br label %79
68: ; preds = %59
%69 = load i8*, i8** %8
%70 = load i32*, i32** %5
%71 = call i32 @fwrite(i8* %69, i32 1, i32 1, i32* %70)
br label %72
72: ; preds = %68, %56
br label %73
73: ; preds = %72
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %11
76: ; preds = %11
%77 = load i8*, i8** %8
%78 = call i32 @free(i8* %77)
store i32 0, i32* %3
br label %79
79: ; preds = %76, %65, %49, %30, %20
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
define i32 @check_luminance(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call i64 @malloc(i32 1)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%6 = icmp slt i32 %5, 1
br i1 %6, label %36, label %7
7: ; preds = %2
%8 = load i8, i8* %4
%9 = icmp eq i8 %8, 50
br i1 %9, label %10, label %33
10: ; preds = %7
%11 = tail call i32 @fputc(i32 50, i32* %1)
%12 = tail call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%13 = icmp slt i32 %12, 1
br i1 %13, label %36, label %14
14: ; preds = %10
%15 = load i8, i8* %4
%16 = icmp eq i8 %15, 53
br i1 %16, label %17, label %33
17: ; preds = %14
%18 = tail call i32 @fputc(i32 53, i32* %1)
%19 = tail call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%20 = icmp slt i32 %19, 1
br i1 %20, label %36, label %21
21: ; preds = %17
%22 = load i8, i8* %4
%23 = icmp eq i8 %22, 53
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = tail call i32 @fputc(i32 53, i32* %1)
%26 = tail call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%27 = icmp slt i32 %26, 1
br i1 %27, label %36, label %28
28: ; preds = %24
%29 = load i8, i8* %4
%30 = icmp eq i8 %29, 10
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 @fputc(i32 10, i32* %1)
br label %33
33: ; preds = %28, %14, %21, %7, %31
%34 = phi i32 [ 0, %31 ], [ 4, %7 ], [ 4, %21 ], [ 4, %14 ], [ 4, %28 ]
%35 = tail call i32 @free(i8* %4)
br label %36
36: ; preds = %33, %2, %10, %17, %24
%37 = phi i32 [ 4, %24 ], [ 4, %17 ], [ 4, %10 ], [ 4, %2 ], [ %34, %33 ]
ret i32 %37
}