#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ isalnum(char);
int sbcs_load_charset_(int /*<<< orphan*/ *, char const *, char const *const,
                       char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strdup(char *);
char *strerror(int /*<<< orphan*/);
char *strndup(char const *, size_t);
void *strrchr(char const *, char);
char *strstr(char const *, char *);
scalar_t__ tolower(char);
scalar_t__ toupper(char);
int main(int argc, char *argv[]) {
  int exit_code = EXIT_FAILURE;
  const char *const name = strrchr(argv[0], '/');
  const char *const program = (name == NULL) ? argv[0] : name + 1;
  if (argc != 2) {
    fprintf(stdout,
            "A charset filename expected:\n"
            "	%s <charset-file>\n",
            program);
  } else {
    const char *file_name = argv[1];
    const char *name_start = strrchr(file_name, '/');
    if (name_start == NULL) {
      name_start = file_name;
    } else {
      name_start++;
    }
    char *ext_start = strstr(name_start, ".TXT");
    if (ext_start == NULL) {
      fprintf(stderr, "Input filename should have \"%s\" suffix.\n", ".TXT");
    } else {
      char *charset_name =
          strndup(name_start, (size_t)(ext_start - name_start));
      if (charset_name == NULL) {
        fprintf(stderr, "Out of memory.\n");
      } else {
        char *user_charset_name = strdup(charset_name);
        if (user_charset_name == NULL) {
          fprintf(stderr, "Out of memory.\n");
        } else {
          FILE *fp = fopen(file_name, "r");
          size_t i = 0;
          while (isalnum(user_charset_name[i]) || user_charset_name[i] == '_' ||
                 user_charset_name[i] == '-') {
            if (user_charset_name[i] == '-') {
              user_charset_name[i] = '_';
              charset_name[i] = '_';
            } else {
              user_charset_name[i] = (char)tolower(user_charset_name[i]);
              charset_name[i] = (char)toupper(charset_name[i]);
            }
            ++i;
          }
          if (user_charset_name[i] != '\0') {
            fprintf(stderr, "A file name has invalid character: '%c'.\n",
                    user_charset_name[i]);
          } else if (fp == NULL) {
            fprintf(stderr, "Failed to open \"%s\": %s.\n", file_name,
                    strerror(errno));
          } else {
            exit_code = sbcs_load_charset_(fp, file_name, program, charset_name,
                                           user_charset_name);
            fclose(fp);
          }
          free(user_charset_name);
        }
        free(charset_name);
      }
    }
  }
  fprintf(stdout, "\n");
  return exit_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1225 <main+0x55>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
jmp    1231 <main+0x61>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1263 <main+0x93>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1524 <main+0x354>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1299 <main+0xc9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    12a5 <main+0xd5>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xd81(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12e7 <main+0x117>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
lea    0xd56(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    151f <main+0x34f>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rax
sub    %rax,%rsi
call   1090 <strndup@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1326 <main+0x156>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    151a <main+0x34a>
mov    -0x48(%rbp),%rdi
call   10d0 <strdup@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    135a <main+0x18a>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
lea    0xd11(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1511 <main+0x341>
mov    -0x30(%rbp),%rdi
lea    0xd0a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x69(%rbp)
jne    13c8 <main+0x1f8>
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x5f,%ecx
mov    %al,-0x69(%rbp)
je     13c8 <main+0x1f8>
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    13d8 <main+0x208>
jmp    1457 <main+0x287>
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    140a <main+0x23a>
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
mov    -0x48(%rbp),%rax
mov    -0x60(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    1446 <main+0x276>
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   10b0 <tolower@plt>
mov    %al,%dl
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x48(%rbp),%rax
mov    -0x60(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
mov    %al,%dl
mov    -0x48(%rbp),%rax
mov    -0x60(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    1376 <main+0x1a6>
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1494 <main+0x2c4>
mov    0x2b6d(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xbe9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1508 <main+0x338>
cmpq   $0x0,-0x58(%rbp)
jne    14de <main+0x30e>
mov    0x2b3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2b1e(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
lea    0xbc9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1503 <main+0x333>
mov    -0x58(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
call   1080 <sbcs_load_charset_@plt>
mov    %eax,-0x14(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1508 <main+0x338>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
jmp    151f <main+0x34f>
jmp    1524 <main+0x354>
mov    0x2a9d(%rip),%rax
mov    (%rax),%edi
lea    0xb65(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
mov    0x2de5(%rip),%rax
mov    (%rax),%r14d
mov    (%rsi),%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
lea    0x1(%rax),%r12
test   %rax,%rax
cmove  %rbp,%r12
cmp    $0x2,%r15d
jne    12fd <main+0x12d>
mov    0x8(%rbx),%r15
mov    %r15,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r15,%rbx
lea    0xdfb(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <strstr@plt>
test   %rax,%rax
je     1312 <main+0x142>
sub    %rbx,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
call   1090 <strndup@plt>
test   %rax,%rax
je     1368 <main+0x198>
mov    %rax,%rbx
mov    %rax,%rdi
call   10d0 <strdup@plt>
test   %rax,%rax
je     1381 <main+0x1b1>
mov    %rax,%rbp
mov    %r14d,0xc(%rsp)
lea    0xdee(%rip),%rsi
mov    %r15,%rdi
call   10c0 <fopen@plt>
mov    %rax,0x10(%rsp)
xor    %r14d,%r14d
jmp    12af <main+0xdf>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x5f,0x0(%rbp,%r14,1)
movb   $0x5f,(%rbx,%r14,1)
add    $0x1,%r14
movsbl 0x0(%rbp,%r14,1),%r13d
mov    %r13d,%edi
call   1060 <isalnum@plt>
test   %rax,%rax
je     12d0 <main+0x100>
cmp    $0x2d,%r13b
je     12a0 <main+0xd0>
jmp    12dc <main+0x10c>
nopw   0x0(%rax,%rax,1)
cmp    $0x2d,%r13b
je     12a0 <main+0xd0>
cmp    $0x5f,%r13b
jne    1335 <main+0x165>
mov    %r13d,%edi
call   10b0 <tolower@plt>
mov    %al,0x0(%rbp,%r14,1)
movsbl (%rbx,%r14,1),%edi
call   1040 <toupper@plt>
mov    %al,(%rbx,%r14,1)
add    $0x1,%r14
jmp    12af <main+0xdf>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xcf3(%rip),%rsi
mov    %r12,%rdx
jmp    1329 <main+0x159>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
lea    0xd14(%rip),%rsi
lea    0xd08(%rip),%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    13fa <main+0x22a>
test   %r13b,%r13b
jne    139a <main+0x1ca>
mov    0x10(%rsp),%r13
test   %r13,%r13
je     13b6 <main+0x1e6>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
call   1080 <sbcs_load_charset_@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1050 <fclose@plt>
jmp    13ea <main+0x21a>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    13fa <main+0x22a>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
lea    0xcce(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    13f2 <main+0x222>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
lea    0xcc7(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    13e5 <main+0x215>
mov    0x2c23(%rip),%rax
mov    (%rax),%r12d
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xcc6(%rip),%rsi
mov    %r12d,%edi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0xc(%rsp),%r14d
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
lea    0xc8f(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str = [49 x i8] c"A charset filename expected:\0A\09%s <charset-file>\0A\00"
@.str.1 = [5 x i8] c".TXT\00"
@stderr = global i32 0
@.str.2 = [41 x i8] c"Input filename should have \22%s\22 suffix.\0A\00"
@.str.3 = [16 x i8] c"Out of memory.\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [42 x i8] c"A file name has invalid character: '%c'.\0A\00"
@.str.6 = [26 x i8] c"Failed to open \22%s\22: %s.\0A\00"
@errno = global i32 0
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i8* @strrchr(i8* %19, i8 signext 47)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
br label %30
27: ; preds = %2
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 1
br label %30
30: ; preds = %27, %23
%31 = phi i8* [ %26, %23 ], [ %29, %27 ]
store i8* %31, i8** %8
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 2
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* @stdout
%36 = load i8*, i8** %8
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %36)
br label %184
38: ; preds = %30
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = call i8* @strrchr(i8* %42, i8 signext 47)
store i8* %43, i8** %10
%44 = load i8*, i8** %10
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = load i8*, i8** %9
store i8* %47, i8** %10
br label %51
48: ; preds = %38
%49 = load i8*, i8** %10
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %10
br label %51
51: ; preds = %48, %46
%52 = load i8*, i8** %10
%53 = call i8* @strstr(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %53, i8** %11
%54 = load i8*, i8** %11
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %183
59: ; preds = %51
%60 = load i8*, i8** %10
%61 = load i8*, i8** %11
%62 = load i8*, i8** %10
%63 = ptrtoint i8* %61 to i64
%64 = ptrtoint i8* %62 to i64
%65 = sub i64 %63, %64
%66 = call i8* @strndup(i8* %60, i64 %65)
store i8* %66, i8** %12
%67 = load i8*, i8** %12
%68 = icmp eq i8* %67, null
br i1 %68, label %69, label %72
69: ; preds = %59
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %182
72: ; preds = %59
%73 = load i8*, i8** %12
%74 = call i8* @strdup(i8* %73)
store i8* %74, i8** %13
%75 = load i8*, i8** %13
%76 = icmp eq i8* %75, null
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %179
80: ; preds = %72
%81 = load i8*, i8** %9
%82 = call i32* @fopen(i8* %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %82, i32** %14
store i64 0, i64* %15
br label %83
83: ; preds = %139, %80
%84 = load i8*, i8** %13
%85 = load i64, i64* %15
%86 = getelementptr inbounds i8, i8* %84, i64 %85
%87 = load i8, i8* %86
%88 = call i64 @isalnum(i8 signext %87)
%89 = icmp ne i64 %88, 0
br i1 %89, label %104, label %90
90: ; preds = %83
%91 = load i8*, i8** %13
%92 = load i64, i64* %15
%93 = getelementptr inbounds i8, i8* %91, i64 %92
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 95
br i1 %96, label %104, label %97
97: ; preds = %90
%98 = load i8*, i8** %13
%99 = load i64, i64* %15
%100 = getelementptr inbounds i8, i8* %98, i64 %99
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = icmp eq i32 %102, 45
br label %104
104: ; preds = %97, %90, %83
%105 = phi i1 [ true, %90 ], [ true, %83 ], [ %103, %97 ]
br i1 %105, label %106, label %142
106: ; preds = %104
%107 = load i8*, i8** %13
%108 = load i64, i64* %15
%109 = getelementptr inbounds i8, i8* %107, i64 %108
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = icmp eq i32 %111, 45
br i1 %112, label %113, label %120
113: ; preds = %106
%114 = load i8*, i8** %13
%115 = load i64, i64* %15
%116 = getelementptr inbounds i8, i8* %114, i64 %115
store i8 95, i8* %116
%117 = load i8*, i8** %12
%118 = load i64, i64* %15
%119 = getelementptr inbounds i8, i8* %117, i64 %118
store i8 95, i8* %119
br label %139
120: ; preds = %106
%121 = load i8*, i8** %13
%122 = load i64, i64* %15
%123 = getelementptr inbounds i8, i8* %121, i64 %122
%124 = load i8, i8* %123
%125 = call i64 @tolower(i8 signext %124)
%126 = trunc i64 %125 to i8
%127 = load i8*, i8** %13
%128 = load i64, i64* %15
%129 = getelementptr inbounds i8, i8* %127, i64 %128
store i8 %126, i8* %129
%130 = load i8*, i8** %12
%131 = load i64, i64* %15
%132 = getelementptr inbounds i8, i8* %130, i64 %131
%133 = load i8, i8* %132
%134 = call i64 @toupper(i8 signext %133)
%135 = trunc i64 %134 to i8
%136 = load i8*, i8** %12
%137 = load i64, i64* %15
%138 = getelementptr inbounds i8, i8* %136, i64 %137
store i8 %135, i8* %138
br label %139
139: ; preds = %120, %113
%140 = load i64, i64* %15
%141 = add i64 %140, 1
store i64 %141, i64* %15
br label %83
142: ; preds = %104
%143 = load i8*, i8** %13
%144 = load i64, i64* %15
%145 = getelementptr inbounds i8, i8* %143, i64 %144
%146 = load i8, i8* %145
%147 = sext i8 %146 to i32
%148 = icmp ne i32 %147, 0
br i1 %148, label %149, label %157
149: ; preds = %142
%150 = load i32, i32* @stderr
%151 = load i8*, i8** %13
%152 = load i64, i64* %15
%153 = getelementptr inbounds i8, i8* %151, i64 %152
%154 = load i8, i8* %153
%155 = sext i8 %154 to i32
%156 = call i32 (i32, i8*, ...) @fprintf(i32 %150, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %155)
br label %176
157: ; preds = %142
%158 = load i32*, i32** %14
%159 = icmp eq i32* %158, null
br i1 %159, label %160, label %166
160: ; preds = %157
%161 = load i32, i32* @stderr
%162 = load i8*, i8** %9
%163 = load i32, i32* @errno
%164 = call i8* @strerror(i32 %163)
%165 = call i32 (i32, i8*, ...) @fprintf(i32 %161, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %162, i8* %164)
br label %175
166: ; preds = %157
%167 = load i32*, i32** %14
%168 = load i8*, i8** %9
%169 = load i8*, i8** %8
%170 = load i8*, i8** %12
%171 = load i8*, i8** %13
%172 = call i32 @sbcs_load_charset_(i32* %167, i8* %168, i8* %169, i8* %170, i8* %171)
store i32 %172, i32* %6
%173 = load i32*, i32** %14
%174 = call i32 @fclose(i32* %173)
br label %175
175: ; preds = %166, %160
br label %176
176: ; preds = %175, %149
%177 = load i8*, i8** %13
%178 = call i32 @free(i8* %177)
br label %179
179: ; preds = %176, %77
%180 = load i8*, i8** %12
%181 = call i32 @free(i8* %180)
br label %182
182: ; preds = %179, %69
br label %183
183: ; preds = %182, %56
br label %184
184: ; preds = %183, %34
%185 = load i32, i32* @stdout
%186 = call i32 (i32, i8*, ...) @fprintf(i32 %185, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%187 = load i32, i32* %6
ret i32 %187
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str = [49 x i8] c"A charset filename expected:\0A\09%s <charset-file>\0A\00"
@.str.1 = [5 x i8] c".TXT\00"
@stderr = global i32 0
@.str.2 = [41 x i8] c"Input filename should have \22%s\22 suffix.\0A\00"
@.str.3 = [16 x i8] c"Out of memory.\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [42 x i8] c"A file name has invalid character: '%c'.\0A\00"
@.str.6 = [26 x i8] c"Failed to open \22%s\22: %s.\0A\00"
@errno = global i32 0
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @EXIT_FAILURE
%4 = load i8*, i8** %1
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %4, i8 signext 47)
%6 = icmp eq i8* %5, null
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = select i1 %6, i8* %4, i8* %7
%9 = icmp eq i32 %0, 2
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %82
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i8* @strrchr(i8* dereferenceable(1) %15, i8 signext 47)
%17 = icmp eq i8* %16, null
%18 = getelementptr inbounds i8, i8* %16, i64 1
%19 = select i1 %17, i8* %15, i8* %18
%20 = tail call i8* @strstr(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %82
25: ; preds = %13
%26 = ptrtoint i8* %20 to i64
%27 = ptrtoint i8* %19 to i64
%28 = sub i64 %26, %27
%29 = tail call i8* @strndup(i8* %19, i64 %28)
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %82
34: ; preds = %25
%35 = tail call i8* @strdup(i8* %29)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %79
40: ; preds = %34
%41 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %60, %40
%43 = phi i64 [ 0, %40 ], [ %61, %60 ]
%44 = getelementptr inbounds i8, i8* %35, i64 %43
%45 = load i8, i8* %44
%46 = tail call i64 @isalnum(i8 signext %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %42
switch i8 %45, label %62 [
i8 0, label %66
i8 45, label %51
i8 95, label %53
]
49: ; preds = %42
%50 = icmp eq i8 %45, 45
br i1 %50, label %51, label %53
51: ; preds = %48, %49
store i8 95, i8* %44
%52 = getelementptr inbounds i8, i8* %29, i64 %43
store i8 95, i8* %52
br label %60
53: ; preds = %48, %49
%54 = tail call i64 @tolower(i8 signext %45)
%55 = trunc i64 %54 to i8
store i8 %55, i8* %44
%56 = getelementptr inbounds i8, i8* %29, i64 %43
%57 = load i8, i8* %56
%58 = tail call i64 @toupper(i8 signext %57)
%59 = trunc i64 %58 to i8
store i8 %59, i8* %56
br label %60
60: ; preds = %53, %51
%61 = add i64 %43, 1
br label %42
62: ; preds = %48
%63 = sext i8 %45 to i32
%64 = load i32, i32* @stderr
%65 = tail call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %63)
br label %76
66: ; preds = %48
%67 = icmp eq i32* %41, null
br i1 %67, label %68, label %73
68: ; preds = %66
%69 = load i32, i32* @stderr
%70 = load i32, i32* @errno
%71 = tail call i8* @strerror(i32 %70)
%72 = tail call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %15, i8* %71)
br label %76
73: ; preds = %66
%74 = tail call i32 @sbcs_load_charset_(i32* %41, i8* %15, i8* %8, i8* %29, i8* %35)
%75 = tail call i32 @fclose(i32* %41)
br label %76
76: ; preds = %68, %73, %62
%77 = phi i32 [ %3, %62 ], [ %3, %68 ], [ %74, %73 ]
%78 = tail call i32 @free(i8* %35)
br label %79
79: ; preds = %76, %37
%80 = phi i32 [ %3, %37 ], [ %77, %76 ]
%81 = tail call i32 @free(i8* %29)
br label %82
82: ; preds = %22, %79, %31, %10
%83 = phi i32 [ %3, %10 ], [ %3, %22 ], [ %3, %31 ], [ %80, %79 ]
%84 = load i32, i32* @stdout
%85 = tail call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret i32 %83
}