#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*/ add_float(int, double);
double atof(char *);
int atoi(char *);
int /*<<< orphan*/ isnormal(double);
int /*<<< orphan*/ print_error(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
char *strtok(char *, char *);
void validate_line(char *line) {
  if (strcmp(line, "\n") == 0) {
    print_error(line, "empty");
    return;
  }
  char lineTMP[512];
  strcpy(lineTMP, line);
  lineTMP[512] = '\0';
  if (strncmp(lineTMP, "#", 1) == 0) {
    print_error(line, "comment");
    return;
  }
  strtok(lineTMP, "'#");
  char *ptr = strtok(lineTMP, ";");
  char *ptrClass = strtok(NULL, ";");
  int loc = atoi(ptrClass);
  if (loc > 2 || loc < 1) {
    print_error(line, "falseLOC");
    return;
  }
  char *ptrFloat = strtok(NULL, ";");
  if (ptrFloat == NULL) {
    print_error(line, "noFloat");
    return;
  }
  double number = atof(ptrFloat);
  if (number <= 0.0 || !isnormal(number)) {
    print_error(line, "falseValue");
    return;
  }
  add_float(loc, number);
}


x86 assembly (clang, -O0):
<validate_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11ce <validate_line+0x3e>
mov    -0x8(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <print_error@plt>
jmp    133b <validate_line+0x1ab>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
movb   $0x0,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
lea    0xe21(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1219 <validate_line+0x89>
mov    -0x8(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1060 <print_error@plt>
jmp    133b <validate_line+0x1ab>
lea    -0x210(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   10a0 <strtok@plt>
lea    -0x210(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x218(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc2(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x2,-0x224(%rbp)
jg     1289 <validate_line+0xf9>
cmpl   $0x1,-0x224(%rbp)
jge    129e <validate_line+0x10e>
mov    -0x8(%rbp),%rdi
lea    0xd81(%rip),%rsi
call   1060 <print_error@plt>
jmp    133b <validate_line+0x1ab>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd6a(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
jne    12d8 <validate_line+0x148>
mov    -0x8(%rbp),%rdi
lea    0xd50(%rip),%rsi
call   1060 <print_error@plt>
jmp    133b <validate_line+0x1ab>
mov    -0x230(%rbp),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0x238(%rbp)
ff
xorps  %xmm0,%xmm0
ucomisd -0x238(%rbp),%xmm0
ff
jae    1313 <validate_line+0x183>
movsd  -0x238(%rbp),%xmm0
ff
call   1090 <isnormal@plt>
cmp    $0x0,%eax
jne    1328 <validate_line+0x198>
mov    -0x8(%rbp),%rdi
lea    0xd08(%rip),%rsi
call   1060 <print_error@plt>
jmp    133b <validate_line+0x1ab>
mov    -0x224(%rbp),%edi
movsd  -0x238(%rbp),%xmm0
ff
call   1080 <add_float@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_line>:
push   %r15
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    %rdi,%r15
lea    0xe5a(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     122e <validate_line+0x9e>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
movb   $0x0,0x210(%rsp)
lea    0xe42(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1249 <validate_line+0xb9>
lea    0xe28(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <strtok@plt>
lea    0xe17(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <strtok@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   10a0 <strtok@plt>
mov    %rax,%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
lea    -0x3(%r14),%eax
cmp    $0xfffffffd,%eax
ja     1252 <validate_line+0xc2>
lea    0xde9(%rip),%rsi
jmp    12a6 <validate_line+0x116>
lea    0xdcd(%rip),%rsi
mov    %r15,%rdi
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <print_error@plt>
lea    0xdb8(%rip),%rsi
jmp    12a6 <validate_line+0x116>
lea    0xdba(%rip),%rsi
xor    %edi,%edi
call   10a0 <strtok@plt>
test   %rax,%rax
je     129f <validate_line+0x10f>
mov    %rax,%rdi
call   1050 <atof@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1296 <validate_line+0x106>
movsd  %xmm0,0x8(%rsp)
call   1090 <isnormal@plt>
movsd  0x8(%rsp),%xmm0
test   %eax,%eax
je     1296 <validate_line+0x106>
mov    %r14d,%edi
call   1080 <add_float@plt>
jmp    12ae <validate_line+0x11e>
lea    0xd89(%rip),%rsi
jmp    12a6 <validate_line+0x116>
lea    0xd78(%rip),%rsi
mov    %r15,%rdi
call   1060 <print_error@plt>
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [6 x i8] c"empty\00"
@.str.2 = [2 x i8] c"#\00"
@.str.3 = [8 x i8] c"comment\00"
@.str.4 = [3 x i8] c"'#\00"
@.str.5 = [2 x i8] c";\00"
@.str.6 = [9 x i8] c"falseLOC\00"
@.str.7 = [8 x i8] c"noFloat\00"
@.str.8 = [11 x i8] c"falseValue\00"
define void @validate_line(i8* %0) {
%2 = alloca i8*
%3 = alloca [512 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca double
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @print_error(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %65
15: ; preds = %1
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%17 = load i8*, i8** %2
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 512
store i8 0, i8* %19
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i8*, i8** %2
%25 = call i32 @print_error(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %65
26: ; preds = %15
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%28 = call i8* @strtok(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%30 = call i8* @strtok(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %30, i8** %4
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp sgt i32 %34, 2
br i1 %35, label %39, label %36
36: ; preds = %26
%37 = load i32, i32* %6
%38 = icmp slt i32 %37, 1
br i1 %38, label %39, label %42
39: ; preds = %36, %26
%40 = load i8*, i8** %2
%41 = call i32 @print_error(i8* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %65
42: ; preds = %36
%43 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i8*, i8** %2
%48 = call i32 @print_error(i8* %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %65
49: ; preds = %42
%50 = load i8*, i8** %7
%51 = call double @atof(i8* %50)
store double %51, double* %8
%52 = load double, double* %8
%53 = fcmp ole double %52, 0.000000e+00
br i1 %53, label %58, label %54
54: ; preds = %49
%55 = load double, double* %8
%56 = call i32 @isnormal(double %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %54, %49
%59 = load i8*, i8** %2
%60 = call i32 @print_error(i8* %59, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %65
61: ; preds = %54
%62 = load i32, i32* %6
%63 = load double, double* %8
%64 = call i32 @add_float(i32 %62, double %63)
br label %65
65: ; preds = %61, %58, %46, %39, %23, %12
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [6 x i8] c"empty\00"
@.str.2 = [2 x i8] c"#\00"
@.str.3 = [8 x i8] c"comment\00"
@.str.4 = [3 x i8] c"'#\00"
@.str.5 = [2 x i8] c";\00"
@.str.6 = [9 x i8] c"falseLOC\00"
@.str.7 = [8 x i8] c"noFloat\00"
@.str.8 = [11 x i8] c"falseValue\00"
define void @validate_line(i8* %0) {
%2 = alloca [512 x i8]
%3 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @print_error(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %40
7: ; preds = %1
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* %0)
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 512
store i8 0, i8* %10
%11 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 @print_error(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %39
15: ; preds = %7
%16 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%17 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%18 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @atoi(i8* %18)
%20 = add i32 %19, -3
%21 = icmp ult i32 %20, -2
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @print_error(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %39
24: ; preds = %15
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @print_error(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %39
29: ; preds = %24
%30 = call double @atof(i8* %25)
%31 = fcmp ugt double %30, 0.000000e+00
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 @isnormal(double %30)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32, %29
%36 = call i32 @print_error(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %39
37: ; preds = %32
%38 = call i32 @add_float(i32 %19, double %30)
br label %39
39: ; preds = %22, %35, %37, %27, %13
br label %40
40: ; preds = %39, %5
ret void
}