#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 /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ trimmer(char *, int *, int, int);
int check_dimensions(int dimensions_array[], int size, FILE *input_file,
                     FILE *output_file) {
  char *dynamic_array = NULL;
  char *width = NULL;
  char *height = NULL;
  int count;
  dynamic_array = (char *)malloc(1 * sizeof(char));
  width = (char *)malloc(4 * sizeof(char));
  height = (char *)malloc(4 * sizeof(char));
  do {
    count = fread(dynamic_array, sizeof(char), 1, input_file);
    if (count <= 0)
      return 4;
    if ((dynamic_array[0] >= '0' && dynamic_array[0] <= '9') ||
        dynamic_array[0] == ' ') {
      strcat(width, dynamic_array);
      fwrite(dynamic_array, sizeof(char), 1, output_file);
    } else {
      free(dynamic_array);
      free(width);
      free(height);
      return 4;
    }
  } while ((dynamic_array[0] >= '0' && dynamic_array[0] <= '9'));
  do {
    count = fread(dynamic_array, sizeof(char), 1, input_file);
    if (count <= 0)
      return 4;
    if ((dynamic_array[0] >= '0' && dynamic_array[0] <= '9') ||
        (strcmp(dynamic_array, "\n") == 0)) {
      strcat(height, dynamic_array);
      fwrite(dynamic_array, sizeof(char), 1, output_file);
    } else {
      free(dynamic_array);
      free(width);
      free(height);
      return 4;
    }
  } while ((dynamic_array[0] >= '0' && dynamic_array[0] <= '9'));
  trimmer(width, dimensions_array, size, 0);
  trimmer(height, dimensions_array, size, 1);
  free(dynamic_array);
  free(width);
  free(height);
  return 0;
}


x86 assembly (clang, -O0):
<check_dimensions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jg     11f6 <check_dimensions+0x86>
movl   $0x4,-0x4(%rbp)
jmp    13df <check_dimensions+0x26f>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1216 <check_dimensions+0xa6>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    1226 <check_dimensions+0xb6>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    124c <check_dimensions+0xdc>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
jmp    1273 <check_dimensions+0x103>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x4,-0x4(%rbp)
jmp    13df <check_dimensions+0x26f>
jmp    1278 <check_dimensions+0x108>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x45(%rbp)
jl     129d <check_dimensions+0x12d>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
test   $0x1,%al
jne    11c9 <check_dimensions+0x59>
jmp    12ad <check_dimensions+0x13d>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jg     12da <check_dimensions+0x16a>
movl   $0x4,-0x4(%rbp)
jmp    13df <check_dimensions+0x26f>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     12fa <check_dimensions+0x18a>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    1314 <check_dimensions+0x1a4>
mov    -0x30(%rbp),%rdi
lea    0xcfb(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    133a <check_dimensions+0x1ca>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
jmp    1361 <check_dimensions+0x1f1>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x4,-0x4(%rbp)
jmp    13df <check_dimensions+0x26f>
jmp    1366 <check_dimensions+0x1f6>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x46(%rbp)
jl     138b <check_dimensions+0x21b>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x46(%rbp)
mov    -0x46(%rbp),%al
test   $0x1,%al
jne    12ad <check_dimensions+0x13d>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1050 <trimmer@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x1,%ecx
call   1050 <trimmer@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
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):
<check_dimensions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %esi,0xc(%rsp)
mov    %rdi,0x10(%rsp)
mov    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x4,%r13d
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
jmp    11df <check_dimensions+0x6f>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
movsbl (%rbx),%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
movzbl (%rbx),%eax
add    $0xd0,%al
cmp    $0xa,%al
jae    1214 <check_dimensions+0xa4>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    12c0 <check_dimensions+0x150>
movzbl (%rbx),%eax
cmp    $0x20,%al
je     11c0 <check_dimensions+0x50>
add    $0xd0,%al
cmp    $0x9,%al
jbe    11c0 <check_dimensions+0x50>
mov    $0x4,%r13d
jmp    12a8 <check_dimensions+0x138>
lea    0xde5(%rip),%r13
jmp    123f <check_dimensions+0xcf>
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
movsbl (%rbx),%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
movzbl (%rbx),%eax
add    $0xd0,%al
cmp    $0xa,%al
jae    127b <check_dimensions+0x10b>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    1273 <check_dimensions+0x103>
movzbl (%rbx),%eax
add    $0xd0,%al
cmp    $0xa,%al
jb     1220 <check_dimensions+0xb0>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1220 <check_dimensions+0xb0>
jmp    1209 <check_dimensions+0x99>
mov    $0x4,%r13d
jmp    12c0 <check_dimensions+0x150>
xor    %r13d,%r13d
mov    %r14,%rdi
mov    0x10(%rsp),%r12
mov    %r12,%rsi
mov    0xc(%rsp),%ebp
mov    %ebp,%edx
xor    %ecx,%ecx
call   1060 <trimmer@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    $0x1,%ecx
call   1060 <trimmer@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @check_dimensions(i32* %0, i32 %1, i32* nocapture %2, i32* nocapture %3) {
%5 = tail call i64 @malloc(i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i64 @malloc(i32 4)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 @malloc(i32 4)
%10 = inttoptr i64 %9 to i8*
br label %11
11: ; preds = %20, %4
%12 = tail call i32 @fread(i8* %6, i32 1, i32 1, i32* %2)
%13 = icmp slt i32 %12, 1
br i1 %13, label %54, label %14
14: ; preds = %11
%15 = load i8, i8* %6
%16 = add i8 %15, -48
%17 = icmp ult i8 %16, 10
%18 = icmp eq i8 %15, 32
%19 = or i1 %18, %17
br i1 %19, label %20, label %49
20: ; preds = %14
%21 = tail call i32 @strcat(i8* %8, i8* %6)
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = tail call i32 @fputc(i32 %23, i32* %3)
%25 = load i8, i8* %6
%26 = add i8 %25, -48
%27 = icmp ult i8 %26, 10
br i1 %27, label %11, label %28
28: ; preds = %20, %38
%29 = tail call i32 @fread(i8* %6, i32 1, i32 1, i32* %2)
%30 = icmp slt i32 %29, 1
br i1 %30, label %54, label %31
31: ; preds = %28
%32 = load i8, i8* %6
%33 = add i8 %32, -48
%34 = icmp ult i8 %33, 10
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %31, %35
%39 = tail call i32 @strcat(i8* %10, i8* %6)
%40 = load i8, i8* %6
%41 = sext i8 %40 to i32
%42 = tail call i32 @fputc(i32 %41, i32* %3)
%43 = load i8, i8* %6
%44 = add i8 %43, -48
%45 = icmp ult i8 %44, 10
br i1 %45, label %28, label %46
46: ; preds = %38
%47 = tail call i32 @trimmer(i8* %8, i32* %0, i32 %1, i32 0)
%48 = tail call i32 @trimmer(i8* %10, i32* %0, i32 %1, i32 1)
br label %49
49: ; preds = %14, %35, %46
%50 = phi i32 [ 0, %46 ], [ 4, %35 ], [ 4, %14 ]
%51 = tail call i32 @free(i8* %6)
%52 = tail call i32 @free(i8* %8)
%53 = tail call i32 @free(i8* %10)
br label %54
54: ; preds = %11, %28, %49
%55 = phi i32 [ %50, %49 ], [ 4, %28 ], [ 4, %11 ]
ret i32 %55
}