#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 error(char *);
int get_nibbles(char *, int);
int rotl16(int, int);
int xtoi(char);
int check_xtcline(char *line) {
  int i, code, datacnt;
  char address_field_used = (!0);
  if (line[0] != '/')
    return error("illegal start character for XTC LDM line");
  switch (line[1]) {
  case 'I':
    code = 0;
    break;
  case 'O':
    code = 1;
    break;
  case 'E':
    code = 2;
    address_field_used = 0;
    break;
  case 'W':
    code = 3;
    address_field_used = 0;
    break;
  case 'D':
    code = 4;
    address_field_used = 0;
    break;
  case 'P':
    code = 5;
    address_field_used = 0;
    break;
  case 'T':
    code = 6;
    break;
  case 'C':
    code = 7;
    break;
  case 'Z':
    code = 8;
    address_field_used = 0;
    break;
  default:
    return error("illegal record type in XTC LDM line");
  }
  if (address_field_used) {
    int addr16 = get_nibbles(line + 3, 4);
    if (addr16 == -1)
      return error("xtcldm: illegal char in address field");
    code = (code << 1) ^ (int)addr16;
  }
  if ((datacnt = xtoi(line[7])) == -1)
    return error("xtcldm: illegal character in data count");
  for (i = 0; i < datacnt; i++) {
    int dataword = get_nibbles(line + 12 + (4 * i), 4);
    if (dataword == -1)
      return error("xtcldm: illegal char in data word");
    code = rotl16(code, 1) ^ (int)dataword;
  }
  return code;
}


x86 assembly (clang, -O0):
<check_xtcline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x1,-0x1d(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1174 <check_xtcline+0x34>
lea    0xef9(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1324 <check_xtcline+0x1e4>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
add    $0xffffffbd,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x17,%eax
ja     1222 <check_xtcline+0xe2>
mov    -0x30(%rbp),%rax
lea    0xe67(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x18(%rbp)
jmp    1236 <check_xtcline+0xf6>
movl   $0x1,-0x18(%rbp)
jmp    1236 <check_xtcline+0xf6>
movl   $0x2,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
jmp    1236 <check_xtcline+0xf6>
movl   $0x3,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
jmp    1236 <check_xtcline+0xf6>
movl   $0x4,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
jmp    1236 <check_xtcline+0xf6>
movl   $0x5,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
jmp    1236 <check_xtcline+0xf6>
movl   $0x6,-0x18(%rbp)
jmp    1236 <check_xtcline+0xf6>
movl   $0x7,-0x18(%rbp)
jmp    1236 <check_xtcline+0xf6>
movl   $0x8,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
jmp    1236 <check_xtcline+0xf6>
lea    0xe60(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1324 <check_xtcline+0x1e4>
cmpb   $0x0,-0x1d(%rbp)
je     127f <check_xtcline+0x13f>
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
mov    $0x4,%esi
call   1040 <get_nibbles@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1273 <check_xtcline+0x133>
lea    0xe47(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1324 <check_xtcline+0x1e4>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
xor    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x7(%rax),%edi
call   1050 <xtoi@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    12ac <check_xtcline+0x16c>
lea    0xe34(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1324 <check_xtcline+0x1e4>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    131e <check_xtcline+0x1de>
mov    -0x10(%rbp),%rdi
add    $0xc,%rdi
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
cltq
add    %rax,%rdi
mov    $0x4,%esi
call   1040 <get_nibbles@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    12fd <check_xtcline+0x1bd>
lea    0xe0b(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1324 <check_xtcline+0x1e4>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1030 <rotl16@plt>
xor    -0x28(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12b3 <check_xtcline+0x173>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_xtcline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmpb   $0x2f,(%rdi)
jne    1185 <check_xtcline+0x45>
mov    %rdi,%r15
movsbl 0x1(%rdi),%eax
lea    0xf2e(%rip),%r14
add    $0xffffffbd,%eax
cmp    $0x17,%eax
ja     1240 <check_xtcline+0x100>
mov    $0x2,%ebp
xor    %ebx,%ebx
lea    0xe8b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0xe,%ebx
jmp    11ab <check_xtcline+0x6b>
lea    0xed4(%rip),%r14
jmp    1240 <check_xtcline+0x100>
mov    $0x4,%ebp
jmp    11d9 <check_xtcline+0x99>
mov    $0x2,%ebx
jmp    11ab <check_xtcline+0x6b>
mov    $0x5,%ebp
jmp    11d9 <check_xtcline+0x99>
mov    $0xc,%ebx
lea    0x3(%r15),%rdi
mov    $0x4,%esi
call   1040 <get_nibbles@plt>
cmp    $0xffffffff,%eax
je     11c4 <check_xtcline+0x84>
mov    %eax,%ebp
xor    %ebx,%ebp
jmp    11d9 <check_xtcline+0x99>
lea    0xee2(%rip),%r14
jmp    1240 <check_xtcline+0x100>
mov    $0x3,%ebp
jmp    11d9 <check_xtcline+0x99>
mov    $0x8,%ebp
movsbl 0x7(%r15),%edi
call   1050 <xtoi@plt>
cmp    $0xffffffff,%eax
je     1239 <check_xtcline+0xf9>
test   %eax,%eax
jle    122e <check_xtcline+0xee>
add    $0xc,%r15
mov    %eax,%r12d
lea    0xf01(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x4,%esi
call   1040 <get_nibbles@plt>
cmp    $0xffffffff,%eax
je     1240 <check_xtcline+0x100>
mov    %eax,%ebx
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <rotl16@plt>
mov    %eax,%ebp
xor    %ebx,%ebp
add    $0x4,%r15
add    $0xffffffffffffffff,%r12
jne    1200 <check_xtcline+0xc0>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe93(%rip),%r14
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <error@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"illegal start character for XTC LDM line\00"
@.str.1 = [36 x i8] c"illegal record type in XTC LDM line\00"
@.str.2 = [38 x i8] c"xtcldm: illegal char in address field\00"
@.str.3 = [40 x i8] c"xtcldm: illegal character in data count\00"
@.str.4 = [34 x i8] c"xtcldm: illegal char in data word\00"
define i32 @check_xtcline(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8 1, i8* %7
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 47
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %2
br label %84
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %31 [
i32 73, label %22
i32 79, label %23
i32 69, label %24
i32 87, label %25
i32 68, label %26
i32 80, label %27
i32 84, label %28
i32 67, label %29
i32 90, label %30
]
22: ; preds = %17
store i32 0, i32* %5
br label %33
23: ; preds = %17
store i32 1, i32* %5
br label %33
24: ; preds = %17
store i32 2, i32* %5
store i8 0, i8* %7
br label %33
25: ; preds = %17
store i32 3, i32* %5
store i8 0, i8* %7
br label %33
26: ; preds = %17
store i32 4, i32* %5
store i8 0, i8* %7
br label %33
27: ; preds = %17
store i32 5, i32* %5
store i8 0, i8* %7
br label %33
28: ; preds = %17
store i32 6, i32* %5
br label %33
29: ; preds = %17
store i32 7, i32* %5
br label %33
30: ; preds = %17
store i32 8, i32* %5
store i8 0, i8* %7
br label %33
31: ; preds = %17
%32 = call i32 @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 %32, i32* %2
br label %84
33: ; preds = %30, %29, %28, %27, %26, %25, %24, %23, %22
%34 = load i8, i8* %7
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %49
36: ; preds = %33
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 3
%39 = call i32 @get_nibbles(i8* %38, i32 4)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store i32 %43, i32* %2
br label %84
44: ; preds = %36
%45 = load i32, i32* %5
%46 = shl i32 %45, 1
%47 = load i32, i32* %8
%48 = xor i32 %46, %47
store i32 %48, i32* %5
br label %49
49: ; preds = %44, %33
%50 = load i8*, i8** %3
%51 = getelementptr inbounds i8, i8* %50, i64 7
%52 = load i8, i8* %51
%53 = call i32 @xtoi(i8 signext %52)
store i32 %53, i32* %6
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %49
%56 = call i32 @error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
store i32 %56, i32* %2
br label %84
57: ; preds = %49
store i32 0, i32* %4
br label %58
58: ; preds = %79, %57
%59 = load i32, i32* %4
%60 = load i32, i32* %6
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %82
62: ; preds = %58
%63 = load i8*, i8** %3
%64 = getelementptr inbounds i8, i8* %63, i64 12
%65 = load i32, i32* %4
%66 = mul nsw i32 4, %65
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %64, i64 %67
%69 = call i32 @get_nibbles(i8* %68, i32 4)
store i32 %69, i32* %9
%70 = load i32, i32* %9
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %74
72: ; preds = %62
%73 = call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
store i32 %73, i32* %2
br label %84
74: ; preds = %62
%75 = load i32, i32* %5
%76 = call i32 @rotl16(i32 %75, i32 1)
%77 = load i32, i32* %9
%78 = xor i32 %76, %77
store i32 %78, i32* %5
br label %79
79: ; preds = %74
%80 = load i32, i32* %4
%81 = add nsw i32 %80, 1
store i32 %81, i32* %4
br label %58
82: ; preds = %58
%83 = load i32, i32* %5
store i32 %83, i32* %2
br label %84
84: ; preds = %82, %72, %55, %42, %31, %15
%85 = load i32, i32* %2
ret i32 %85
}

LLVM IR (-O2):
@.str = [41 x i8] c"illegal start character for XTC LDM line\00"
@.str.1 = [36 x i8] c"illegal record type in XTC LDM line\00"
@.str.2 = [38 x i8] c"xtcldm: illegal char in address field\00"
@.str.3 = [40 x i8] c"xtcldm: illegal character in data count\00"
@.str.4 = [34 x i8] c"xtcldm: illegal char in data word\00"
define i32 @check_xtcline(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
br i1 %3, label %4, label %45
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %45 [
i32 73, label %15
i32 79, label %8
i32 69, label %22
i32 87, label %9
i32 68, label %10
i32 80, label %11
i32 84, label %12
i32 67, label %13
i32 90, label %14
]
8: ; preds = %4
br label %15
9: ; preds = %4
br label %22
10: ; preds = %4
br label %22
11: ; preds = %4
br label %22
12: ; preds = %4
br label %15
13: ; preds = %4
br label %15
14: ; preds = %4
br label %22
15: ; preds = %8, %12, %13, %4
%16 = phi i32 [ 14, %13 ], [ 12, %12 ], [ 2, %8 ], [ 0, %4 ]
%17 = getelementptr inbounds i8, i8* %0, i64 3
%18 = tail call i32 @get_nibbles(i8* %17, i32 4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %45, label %20
20: ; preds = %15
%21 = xor i32 %18, %16
br label %22
22: ; preds = %4, %9, %10, %11, %14, %20
%23 = phi i32 [ %21, %20 ], [ 3, %9 ], [ 4, %10 ], [ 5, %11 ], [ 8, %14 ], [ 2, %4 ]
%24 = getelementptr inbounds i8, i8* %0, i64 7
%25 = load i8, i8* %24
%26 = tail call i32 @xtoi(i8 signext %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %45, label %28
28: ; preds = %22
%29 = icmp sgt i32 %26, 0
br i1 %29, label %30, label %48
30: ; preds = %28
%31 = getelementptr inbounds i8, i8* %0, i64 12
%32 = zext i32 %26 to i64
br label %33
33: ; preds = %30, %40
%34 = phi i64 [ 0, %30 ], [ %43, %40 ]
%35 = phi i32 [ %23, %30 ], [ %42, %40 ]
%36 = shl nsw i64 %34, 2
%37 = getelementptr inbounds i8, i8* %31, i64 %36
%38 = tail call i32 @get_nibbles(i8* %37, i32 4)
%39 = icmp eq i32 %38, -1
br i1 %39, label %45, label %40
40: ; preds = %33
%41 = tail call i32 @rotl16(i32 %35, i32 1)
%42 = xor i32 %41, %38
%43 = add nuw nsw i64 %34, 1
%44 = icmp eq i64 %43, %32
br i1 %44, label %48, label %33
45: ; preds = %33, %22, %15, %4, %1
%46 = phi i8* [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), %22 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), %33 ]
%47 = tail call i32 @error(i8* %46)
br label %48
48: ; preds = %40, %45, %28
%49 = phi i32 [ %23, %28 ], [ %47, %45 ], [ %42, %40 ]
ret i32 %49
}