#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__ isspace(int);
char *strchr(char *, char);
int strlen(char *);
int line_chk(char *pBuf) {
  char *p;
  if (pBuf == NULL)
    return -1;
  if ((p = strchr(pBuf, '\n')) != NULL)
    *p = 0;
  if ((p = strchr(pBuf, '\r')) != NULL)
    *p = 0;
  while (isspace((int)*(pBuf + strlen(pBuf) - 1)))
    *(pBuf + strlen(pBuf) - 1) = 0;
  if (*pBuf == ';')
    return -1;
  if (strchr(pBuf, ',') == NULL)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<line_chk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <line_chk+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <line_chk+0x107>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1176 <line_chk+0x46>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1199 <line_chk+0x69>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    119e <line_chk+0x6e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
movsbl -0x1(%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11f0 <line_chk+0xc0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
jmp    119e <line_chk+0x6e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    120c <line_chk+0xdc>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <line_chk+0x107>
mov    -0x10(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1230 <line_chk+0x100>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <line_chk+0x107>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<line_chk>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     11b0 <line_chk+0x80>
mov    %rdi,%rbx
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1152 <line_chk+0x22>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     117f <line_chk+0x4f>
movb   $0x0,(%rax)
jmp    117f <line_chk+0x4f>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rbx,%rax,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    1170 <line_chk+0x40>
cmpb   $0x3b,(%rbx)
je     11b0 <line_chk+0x80>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
cmp    $0x1,%rax
sbb    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @line_chk(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %51
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i8* @strchr(i8* %9, i8 signext 10)
store i8* %10, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = load i8*, i8** %4
store i8 0, i8* %13
br label %14
14: ; preds = %12, %8
%15 = load i8*, i8** %3
%16 = call i8* @strchr(i8* %15, i8 signext 13)
store i8* %16, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i8*, i8** %4
store i8 0, i8* %19
br label %20
20: ; preds = %18, %14
br label %21
21: ; preds = %32, %20
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 -1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i64 @isspace(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %21
%33 = load i8*, i8** %3
%34 = load i8*, i8** %3
%35 = call i32 @strlen(i8* %34)
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = getelementptr inbounds i8, i8* %37, i64 -1
store i8 0, i8* %38
br label %21
39: ; preds = %21
%40 = load i8*, i8** %3
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 59
br i1 %43, label %44, label %45
44: ; preds = %39
store i32 -1, i32* %2
br label %51
45: ; preds = %39
%46 = load i8*, i8** %3
%47 = call i8* @strchr(i8* %46, i8 signext 44)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %50
49: ; preds = %45
store i32 -1, i32* %2
br label %51
50: ; preds = %45
store i32 0, i32* %2
br label %51
51: ; preds = %50, %49, %44, %7
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
define i32 @line_chk(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %41, label %3
3: ; preds = %1
%4 = tail call i8* @strchr(i8* %0, i8 signext 10)
%5 = icmp eq i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %3
store i8 0, i8* %4
br label %7
7: ; preds = %6, %3
%8 = tail call i8* @strchr(i8* %0, i8 signext 13)
%9 = icmp eq i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %7
store i8 0, i8* %8
br label %11
11: ; preds = %10, %7
%12 = tail call i32 @strlen(i8* %0)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = tail call i64 @isspace(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %34, label %20
20: ; preds = %11
%21 = getelementptr inbounds i8, i8* %0, i64 -1
%22 = getelementptr inbounds i8, i8* %0, i64 -1
br label %23
23: ; preds = %20, %23
%24 = tail call i32 @strlen(i8* %0)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %21, i64 %25
store i8 0, i8* %26
%27 = tail call i32 @strlen(i8* %0)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %22, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = tail call i64 @isspace(i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %23
34: ; preds = %23, %11
%35 = load i8, i8* %0
%36 = icmp eq i8 %35, 59
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = tail call i8* @strchr(i8* %0, i8 signext 44)
%39 = icmp eq i8* %38, null
%40 = sext i1 %39 to i32
br label %41
41: ; preds = %37, %34, %1
%42 = phi i32 [ -1, %1 ], [ -1, %34 ], [ %40, %37 ]
ret i32 %42
}