#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 _detect(unsigned char *, int /*<<< orphan*/);
int _detect_euc_or_sjis(unsigned char *);
int detectKanjiCode(char *str) {
  static int detected = 0;
  if (!str)
    return (0);
  detected = _detect((unsigned char *)str, 0);
  if (detected == 4 || detected == 5 || detected == 6)
    return 1;
  if (detected == 7)
    detected = _detect_euc_or_sjis((unsigned char *)str);
  return detected;
}


x86 assembly (clang, -O0):
<detectKanjiCode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <detectKanjiCode+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11ac <detectKanjiCode+0x8c>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <_detect@plt>
mov    %eax,0x2ee0(%rip)
cmpl   $0x4,0x2ed9(%rip)
je     117b <detectKanjiCode+0x5b>
cmpl   $0x5,0x2ecc(%rip)
je     117b <detectKanjiCode+0x5b>
cmpl   $0x6,0x2ebf(%rip)
jne    1187 <detectKanjiCode+0x67>
movl   $0x1,-0x4(%rbp)
jmp    11ac <detectKanjiCode+0x8c>
cmpl   $0x7,0x2ea6(%rip)
jne    11a3 <detectKanjiCode+0x83>
mov    -0x10(%rbp),%rdi
call   1040 <_detect_euc_or_sjis@plt>
mov    %eax,0x2e91(%rip)
mov    0x2e8b(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detectKanjiCode>:
push   %rbx
test   %rdi,%rdi
je     114e <detectKanjiCode+0x2e>
mov    %rdi,%rbx
xor    %esi,%esi
call   1030 <_detect@plt>
mov    $0x1,%ecx
lea    -0x4(%rax),%edx
cmp    $0x3,%edx
jb     1150 <detectKanjiCode+0x30>
cmp    $0x7,%eax
jne    114a <detectKanjiCode+0x2a>
mov    %rbx,%rdi
call   1040 <_detect_euc_or_sjis@plt>
mov    %eax,%ecx
jmp    1150 <detectKanjiCode+0x30>
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@detectKanjiCode.detected = internal global i32 0
define i32 @detectKanjiCode(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store i32 0, i32* %2
br label %27
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i32 @_detect(i8* %8, i32 0)
store i32 %9, i32* @detectKanjiCode.detected
%10 = load i32, i32* @detectKanjiCode.detected
%11 = icmp eq i32 %10, 4
br i1 %11, label %18, label %12
12: ; preds = %7
%13 = load i32, i32* @detectKanjiCode.detected
%14 = icmp eq i32 %13, 5
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* @detectKanjiCode.detected
%17 = icmp eq i32 %16, 6
br i1 %17, label %18, label %19
18: ; preds = %15, %12, %7
store i32 1, i32* %2
br label %27
19: ; preds = %15
%20 = load i32, i32* @detectKanjiCode.detected
%21 = icmp eq i32 %20, 7
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = call i32 @_detect_euc_or_sjis(i8* %23)
store i32 %24, i32* @detectKanjiCode.detected
br label %25
25: ; preds = %22, %19
%26 = load i32, i32* @detectKanjiCode.detected
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %18, %6
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @detectKanjiCode(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = tail call i32 @_detect(i8* %0, i32 0)
switch i32 %4, label %7 [
i32 6, label %9
i32 5, label %9
i32 4, label %9
i32 7, label %5
]
5: ; preds = %3
%6 = tail call i32 @_detect_euc_or_sjis(i8* %0)
br label %7
7: ; preds = %3, %5
%8 = phi i32 [ %4, %3 ], [ %6, %5 ]
br label %9
9: ; preds = %3, %3, %3, %1, %7
%10 = phi i32 [ %8, %7 ], [ 0, %1 ], [ 1, %3 ], [ 1, %3 ], [ 1, %3 ]
ret i32 %10
}