#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_ldmline(char *line) {
  int i, code, datacnt;
  char address_field_used = (!0), cmd_m_c_t = 0;
  if (line[0] != '/')
    return error("ldm: illegal start character for LDM line");
  switch (line[1]) {
  case 'M':
    cmd_m_c_t = (!0);
  case 'I':
  case 'O':
    code = 0x9;
    break;
  case 'N':
    code = 0xA;
    break;
  case 'L':
    code = 0xA + (*(line + 5) - '0');
    break;
  case 'Q':
    code = 0xB;
    break;
  case 'A':
    address_field_used = 0;
    code = 0x6;
    break;
  case 'T':
    code = 0x6;
    cmd_m_c_t = (!0);
    break;
  case 'Z':
    address_field_used = 0;
  case 'G':
  case 'H':
    code = 0x8;
    break;
  case 'C':
    cmd_m_c_t = (!0);
  case 'B':
  case 'P':
    code = 0xE;
    break;
  default:
    return error("illegal Command type in TLD LDM line");
  }
  code <<= 1;
  if (address_field_used) {
    int addr_hinibble = xtoi(line[2]);
    int addr16 = get_nibbles(line + 2 + 1, 4);
    if (addr16 == -1)
      return error("ldm: illegal char in address field");
    code ^= (int)addr16;
    if (addr_hinibble == -1)
      return error("ldm: illegal char in MS-nibble of address");
    if (cmd_m_c_t)
      code = rotl16(code, 1) ^ addr_hinibble;
  }
  if ((datacnt = xtoi(line[7])) == -1)
    return error("ldm: 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("ldm: illegal char in data word");
    code = rotl16(code, 1) ^ (int)dataword;
  }
  return code;
}


x86 assembly (clang, -O0):
<check_ldmline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x1,-0x1d(%rbp)
movb   $0x0,-0x1e(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1178 <check_ldmline+0x38>
lea    0xefd(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1380 <check_ldmline+0x240>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x19,%eax
ja     1224 <check_ldmline+0xe4>
mov    -0x38(%rbp),%rax
lea    0xe63(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x1,-0x1e(%rbp)
movl   $0x9,-0x18(%rbp)
jmp    1238 <check_ldmline+0xf8>
movl   $0xa,-0x18(%rbp)
jmp    1238 <check_ldmline+0xf8>
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%eax
sub    $0x30,%eax
add    $0xa,%eax
mov    %eax,-0x18(%rbp)
jmp    1238 <check_ldmline+0xf8>
movl   $0xb,-0x18(%rbp)
jmp    1238 <check_ldmline+0xf8>
movb   $0x0,-0x1d(%rbp)
movl   $0x6,-0x18(%rbp)
jmp    1238 <check_ldmline+0xf8>
movl   $0x6,-0x18(%rbp)
movb   $0x1,-0x1e(%rbp)
jmp    1238 <check_ldmline+0xf8>
movb   $0x0,-0x1d(%rbp)
movl   $0x8,-0x18(%rbp)
jmp    1238 <check_ldmline+0xf8>
movb   $0x1,-0x1e(%rbp)
movl   $0xe,-0x18(%rbp)
jmp    1238 <check_ldmline+0xf8>
lea    0xe67(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1380 <check_ldmline+0x240>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpb   $0x0,-0x1d(%rbp)
je     12db <check_ldmline+0x19b>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1050 <xtoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
add    $0x1,%rdi
mov    $0x4,%esi
call   1040 <get_nibbles@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1292 <check_ldmline+0x152>
lea    0xe32(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1380 <check_ldmline+0x240>
mov    -0x28(%rbp),%eax
xor    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12b9 <check_ldmline+0x179>
lea    0xe2e(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1380 <check_ldmline+0x240>
cmpb   $0x0,-0x1e(%rbp)
je     12d6 <check_ldmline+0x196>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1030 <rotl16@plt>
xor    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    12db <check_ldmline+0x19b>
mov    -0x10(%rbp),%rax
movsbl 0x7(%rax),%edi
call   1050 <xtoi@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1308 <check_ldmline+0x1c8>
lea    0xe09(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1380 <check_ldmline+0x240>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    137a <check_ldmline+0x23a>
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,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1359 <check_ldmline+0x219>
lea    0xddd(%rip),%rdi
call   1060 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1380 <check_ldmline+0x240>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1030 <rotl16@plt>
xor    -0x2c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    130f <check_ldmline+0x1cf>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_ldmline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmpb   $0x2f,(%rdi)
jne    1193 <check_ldmline+0x53>
mov    %rdi,%r15
movsbl 0x1(%rdi),%ecx
lea    0xf37(%rip),%r14
add    $0xffffffbf,%ecx
cmp    $0x19,%ecx
ja     1290 <check_ldmline+0x150>
mov    $0x10,%ebx
mov    $0xc,%ebp
mov    $0x12,%eax
xor    %r12d,%r12d
lea    0xe80(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x1,%r12b
mov    $0x1c,%eax
jmp    11ca <check_ldmline+0x8a>
lea    0xece(%rip),%r14
jmp    1290 <check_ldmline+0x150>
movsbl 0x5(%r15),%eax
add    %eax,%eax
add    $0xffffffb4,%eax
xor    %r12d,%r12d
jmp    11ca <check_ldmline+0x8a>
mov    $0x14,%eax
xor    %r12d,%r12d
jmp    11ca <check_ldmline+0x8a>
mov    $0x16,%eax
xor    %r12d,%r12d
jmp    11ca <check_ldmline+0x8a>
mov    $0xc,%eax
mov    $0x1,%r12b
mov    %eax,%ebx
movsbl 0x2(%r15),%edi
call   1050 <xtoi@plt>
mov    %eax,%r14d
lea    0x3(%r15),%rdi
mov    $0x4,%esi
call   1040 <get_nibbles@plt>
cmp    $0xffffffff,%eax
je     120e <check_ldmline+0xce>
cmp    $0xffffffff,%r14d
je     1217 <check_ldmline+0xd7>
mov    %eax,%ebp
xor    %ebx,%ebp
test   %r12b,%r12b
je     1225 <check_ldmline+0xe5>
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <rotl16@plt>
mov    %eax,%ebp
xor    %r14d,%ebp
jmp    1225 <check_ldmline+0xe5>
lea    0xea2(%rip),%r14
jmp    1290 <check_ldmline+0x150>
lea    0xebc(%rip),%r14
jmp    1290 <check_ldmline+0x150>
mov    $0x10,%ebp
movsbl 0x7(%r15),%edi
call   1050 <xtoi@plt>
cmp    $0xffffffff,%eax
je     1289 <check_ldmline+0x149>
test   %eax,%eax
jle    127e <check_ldmline+0x13e>
add    $0xc,%r15
mov    %eax,%r12d
lea    0xee3(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x4,%esi
call   1040 <get_nibbles@plt>
cmp    $0xffffffff,%eax
je     1290 <check_ldmline+0x150>
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    1250 <check_ldmline+0x110>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe74(%rip),%r14
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <error@plt>

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

LLVM IR (-O2):
@.str = [42 x i8] c"ldm: illegal start character for LDM line\00"
@.str.1 = [37 x i8] c"illegal Command type in TLD LDM line\00"
@.str.2 = [35 x i8] c"ldm: illegal char in address field\00"
@.str.3 = [42 x i8] c"ldm: illegal char in MS-nibble of address\00"
@.str.4 = [37 x i8] c"ldm: illegal character in data count\00"
@.str.5 = [31 x i8] c"ldm: illegal char in data word\00"
define i32 @check_ldmline(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
br i1 %3, label %4, label %65
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 %65 [
i32 77, label %8
i32 73, label %22
i32 79, label %22
i32 78, label %9
i32 76, label %10
i32 81, label %16
i32 65, label %42
i32 84, label %17
i32 90, label %18
i32 71, label %25
i32 72, label %25
i32 67, label %19
i32 66, label %20
i32 80, label %20
]
8: ; preds = %4
br label %22
9: ; preds = %4
br label %22
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %0, i64 5
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = shl nsw i32 %13, 1
%15 = add nsw i32 %14, -76
br label %22
16: ; preds = %4
br label %22
17: ; preds = %4
br label %22
18: ; preds = %4
br label %42
19: ; preds = %4
br label %20
20: ; preds = %4, %4, %19
%21 = phi i8 [ 0, %4 ], [ 0, %4 ], [ 1, %19 ]
br label %22
22: ; preds = %20, %17, %16, %10, %9, %4, %4, %8
%23 = phi i8 [ 1, %8 ], [ 0, %4 ], [ 0, %4 ], [ 0, %9 ], [ 0, %10 ], [ 0, %16 ], [ 1, %17 ], [ %21, %20 ]
%24 = phi i32 [ 18, %8 ], [ 18, %4 ], [ 18, %4 ], [ 20, %9 ], [ %15, %10 ], [ 22, %16 ], [ 12, %17 ], [ 28, %20 ]
br label %25
25: ; preds = %4, %4, %22
%26 = phi i32 [ %24, %22 ], [ 16, %4 ], [ 16, %4 ]
%27 = phi i8 [ %23, %22 ], [ 0, %4 ], [ 0, %4 ]
%28 = getelementptr inbounds i8, i8* %0, i64 2
%29 = load i8, i8* %28
%30 = tail call i32 @xtoi(i8 signext %29)
%31 = getelementptr inbounds i8, i8* %0, i64 3
%32 = tail call i32 @get_nibbles(i8* %31, i32 4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %65, label %34
34: ; preds = %25
%35 = xor i32 %32, %26
%36 = icmp eq i32 %30, -1
br i1 %36, label %65, label %37
37: ; preds = %34
%38 = icmp eq i8 %27, 0
br i1 %38, label %42, label %39
39: ; preds = %37
%40 = tail call i32 @rotl16(i32 %35, i32 1)
%41 = xor i32 %40, %30
br label %42
42: ; preds = %37, %39, %4, %18
%43 = phi i32 [ 16, %18 ], [ 12, %4 ], [ %35, %37 ], [ %41, %39 ]
%44 = getelementptr inbounds i8, i8* %0, i64 7
%45 = load i8, i8* %44
%46 = tail call i32 @xtoi(i8 signext %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %65, label %48
48: ; preds = %42
%49 = icmp sgt i32 %46, 0
br i1 %49, label %50, label %68
50: ; preds = %48
%51 = getelementptr inbounds i8, i8* %0, i64 12
%52 = zext i32 %46 to i64
br label %53
53: ; preds = %50, %60
%54 = phi i64 [ 0, %50 ], [ %63, %60 ]
%55 = phi i32 [ %43, %50 ], [ %62, %60 ]
%56 = shl nsw i64 %54, 2
%57 = getelementptr inbounds i8, i8* %51, i64 %56
%58 = tail call i32 @get_nibbles(i8* %57, i32 4)
%59 = icmp eq i32 %58, -1
br i1 %59, label %65, label %60
60: ; preds = %53
%61 = tail call i32 @rotl16(i32 %55, i32 1)
%62 = xor i32 %61, %58
%63 = add nuw nsw i64 %54, 1
%64 = icmp eq i64 %63, %52
br i1 %64, label %68, label %53
65: ; preds = %53, %42, %34, %25, %4, %1
%66 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), %25 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), %34 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), %42 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), %53 ]
%67 = tail call i32 @error(i8* %66)
br label %68
68: ; preds = %60, %65, %48
%69 = phi i32 [ %43, %48 ], [ %67, %65 ], [ %62, %60 ]
ret i32 %69
}