#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*/ abort();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strtoul(unsigned char *, int /*<<< orphan*/ *, int);
int JIS0212(unsigned char *ptr) {
  int i = 0;
  unsigned int fmap;
  unsigned int ucs;
  *(ptr + 6) = '\0';
  fmap = (unsigned int)strtoul(ptr, NULL, 16);
  ptr += 7;
  i += 7;
  while (*ptr == ' ') {
    ptr++;
    i++;
  }
  *(ptr + 6) = '\0';
  ucs = (unsigned int)strtoul(ptr, NULL, 16);
  if (*(ptr + 1) != 'x') {
    printf("/* EOF */\n");
    abort();
  }
  if (ucs)
    printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs, (fmap & 0xFF00) >> 8,
           fmap & 0xFF);
  while (*ptr != '\0') {
    ptr++;
    i++;
  }
  i++;
  ptr++;
  while (*ptr != '\n') {
    ptr++;
    i++;
  }
  i++;
  return i;
}


x86 assembly (clang, -O0):
<JIS0212>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,0x6(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jne    119f <JIS0212+0x6f>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <JIS0212+0x45>
mov    -0x8(%rbp),%rax
movb   $0x0,0x6(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     11e2 <JIS0212+0xb2>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x0,-0x14(%rbp)
je     1212 <JIS0212+0xe2>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
and    $0xff00,%edx
shr    $0x8,%edx
mov    -0x10(%rbp),%ecx
and    $0xff,%ecx
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1217 <JIS0212+0xe7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     1241 <JIS0212+0x111>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1217 <JIS0212+0xe7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa,%eax
je     1280 <JIS0212+0x150>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1256 <JIS0212+0x126>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<JIS0212>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
movb   $0x0,0x6(%rdi)
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %rax,%r15
lea    0x7(%r14),%rax
mov    $0x7,%ebx
cmpb   $0x20,0x7(%r14)
jne    1182 <JIS0212+0x42>
mov    $0x7,%ebx
lea    0x1(%rax),%r14
add    $0x1,%ebx
cmpb   $0x20,0x1(%rax)
mov    %r14,%rax
je     1170 <JIS0212+0x30>
jmp    1185 <JIS0212+0x45>
mov    %rax,%r14
movb   $0x0,0x6(%r14)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
cmpb   $0x78,0x1(%r14)
jne    1204 <JIS0212+0xc4>
test   %eax,%eax
je     11bd <JIS0212+0x7d>
mov    %r15,%rcx
movzbl %ch,%edx
movzbl %cl,%ecx
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpb   $0x0,(%r14)
je     11e3 <JIS0212+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%r14),%rax
add    $0x1,%ebx
cmpb   $0x0,0x1(%r14)
mov    %rax,%r14
jne    11d0 <JIS0212+0x90>
jmp    11e6 <JIS0212+0xa6>
mov    %r14,%rax
add    $0x1,%ebx
add    $0x1,%rax
nopl   (%rax)
add    $0x1,%ebx
cmpb   $0xa,(%rax)
lea    0x1(%rax),%rax
jne    11f0 <JIS0212+0xb0>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe13(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/* EOF */\0A\00"
@.str.1 = [30 x i8] c"/* U+%04X */ 0x%02X, 0x%02X,\0A\00"
define i32 @JIS0212(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 6
store i8 0, i8* %7
%8 = load i8*, i8** %2
%9 = call i64 @strtoul(i8* %8, i32* null, i32 16)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %4
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 7
store i8* %12, i8** %2
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 7
store i32 %14, i32* %3
br label %15
15: ; preds = %20, %1
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %2
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %15
25: ; preds = %15
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i64 6
store i8 0, i8* %27
%28 = load i8*, i8** %2
%29 = call i64 @strtoul(i8* %28, i32* null, i32 16)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %5
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = icmp ne i32 %34, 120
br i1 %35, label %36, label %39
36: ; preds = %25
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%38 = call i32 (...) @abort()
unreachable
39: ; preds = %25
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = load i32, i32* %5
%44 = load i32, i32* %4
%45 = and i32 %44, 65280
%46 = lshr i32 %45, 8
%47 = load i32, i32* %4
%48 = and i32 %47, 255
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %46, i32 %48)
br label %50
50: ; preds = %42, %39
br label %51
51: ; preds = %56, %50
%52 = load i8*, i8** %2
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = load i8*, i8** %2
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %2
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 1
store i32 %60, i32* %3
br label %51
61: ; preds = %51
%62 = load i32, i32* %3
%63 = add nsw i32 %62, 1
store i32 %63, i32* %3
%64 = load i8*, i8** %2
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %2
br label %66
66: ; preds = %71, %61
%67 = load i8*, i8** %2
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = icmp ne i32 %69, 10
br i1 %70, label %71, label %76
71: ; preds = %66
%72 = load i8*, i8** %2
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %2
%74 = load i32, i32* %3
%75 = add nsw i32 %74, 1
store i32 %75, i32* %3
br label %66
76: ; preds = %66
%77 = load i32, i32* %3
%78 = add nsw i32 %77, 1
store i32 %78, i32* %3
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"/* U+%04X */ 0x%02X, 0x%02X,\0A\00"
@str = [10 x i8] c"/* EOF */\00"
define i32 @JIS0212(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 6
store i8 0, i8* %2
%3 = tail call i64 @strtoul(i8* nocapture %0, i32* null, i32 16)
%4 = trunc i64 %3 to i32
%5 = getelementptr inbounds i8, i8* %0, i64 7
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 32
br i1 %7, label %8, label %15
8: ; preds = %1, %8
%9 = phi i8* [ %11, %8 ], [ %5, %1 ]
%10 = phi i32 [ %12, %8 ], [ 7, %1 ]
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = add nuw nsw i32 %10, 1
%13 = load i8, i8* %11
%14 = icmp eq i8 %13, 32
br i1 %14, label %8, label %15
15: ; preds = %8, %1
%16 = phi i32 [ 7, %1 ], [ %12, %8 ]
%17 = phi i8* [ %5, %1 ], [ %11, %8 ]
%18 = getelementptr inbounds i8, i8* %17, i64 6
store i8 0, i8* %18
%19 = tail call i64 @strtoul(i8* nocapture %17, i32* null, i32 16)
%20 = trunc i64 %19 to i32
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 120
br i1 %23, label %27, label %24
24: ; preds = %15
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%26 = tail call i32 (...) @abort()
unreachable
27: ; preds = %15
%28 = icmp eq i32 %20, 0
br i1 %28, label %34, label %29
29: ; preds = %27
%30 = lshr i32 %4, 8
%31 = and i32 %30, 255
%32 = and i32 %4, 255
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %31, i32 %32)
br label %34
34: ; preds = %29, %27
%35 = load i8, i8* %17
%36 = icmp eq i8 %35, 0
br i1 %36, label %44, label %37
37: ; preds = %34, %37
%38 = phi i8* [ %40, %37 ], [ %17, %34 ]
%39 = phi i32 [ %41, %37 ], [ %16, %34 ]
%40 = getelementptr inbounds i8, i8* %38, i64 1
%41 = add nuw nsw i32 %39, 1
%42 = load i8, i8* %40
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %37
44: ; preds = %37, %34
%45 = phi i32 [ %16, %34 ], [ %41, %37 ]
%46 = phi i8* [ %17, %34 ], [ %40, %37 ]
br label %47
47: ; preds = %44, %47
%48 = phi i32 [ %53, %47 ], [ %45, %44 ]
%49 = phi i8* [ %50, %47 ], [ %46, %44 ]
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = icmp eq i8 %51, 10
%53 = add nuw nsw i32 %48, 1
br i1 %52, label %54, label %47
54: ; preds = %47
%55 = add nuw nsw i32 %48, 2
ret i32 %55
}