#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*/ exists_word(char *);
int get_wordid(char *, int);
int /*<<< orphan*/ put_word(int, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void process_chinese_word(int fileid, int pos, char *word) {
  int i, j, len = strlen(word), wordid;
  char tmp[1024];
  i = 0;
  while (i < len) {
    j = len - i;
    if (j > 10)
      j = 10;
    strncpy(tmp, word + i, j);
    tmp[j] = 0;
    while (!exists_word(tmp) && j > 2) {
      j -= 2;
      strncpy(tmp, word + i, j);
      tmp[j] = 0;
    }
    wordid = get_wordid(tmp, 1);
    put_word(wordid, pos + i);
    i += j;
  }
}


x86 assembly (clang, -O0):
<process_chinese_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1267 <process_chinese_word+0x117>
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jle    119e <process_chinese_word+0x4e>
movl   $0xa,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
call   1050 <exists_word@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x421(%rbp)
jne    11f0 <process_chinese_word+0xa0>
cmpl   $0x2,-0x18(%rbp)
setg   %al
mov    %al,-0x421(%rbp)
mov    -0x421(%rbp),%al
test   $0x1,%al
jne    1203 <process_chinese_word+0xb3>
jmp    1237 <process_chinese_word+0xe7>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
jmp    11c4 <process_chinese_word+0x74>
lea    -0x420(%rbp),%rdi
mov    $0x1,%esi
call   1070 <get_wordid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%esi
add    -0x14(%rbp),%esi
call   1060 <put_word@plt>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1178 <process_chinese_word+0x28>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_chinese_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rdx,%rdi
mov    %rsi,0x10(%rsp)
mov    %rdx,0x18(%rsp)
call   1040 <strlen@plt>
test   %eax,%eax
jle    1249 <process_chinese_word+0xf9>
xor    %r12d,%r12d
lea    0x20(%rsp),%r13
mov    %eax,0xc(%rsp)
jmp    11c0 <process_chinese_word+0x70>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    $0x1,%esi
call   1070 <get_wordid@plt>
mov    0x10(%rsp),%rcx
lea    (%r12,%rcx,1),%esi
mov    %eax,%edi
call   1060 <put_word@plt>
add    %r12d,%r15d
mov    %r15d,%r12d
mov    0xc(%rsp),%eax
cmp    %r15d,%eax
jle    1249 <process_chinese_word+0xf9>
mov    %eax,%r15d
sub    %r12d,%r15d
cmp    $0xa,%r15d
mov    $0xa,%eax
cmovge %eax,%r15d
movslq %r12d,%rbx
add    0x18(%rsp),%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movslq %r15d,%r14
movb   $0x0,0x20(%rsp,%r14,1)
mov    %r13,%rdi
call   1050 <exists_word@plt>
cmp    $0x3,%r14d
jl     1190 <process_chinese_word+0x40>
test   %eax,%eax
jne    1190 <process_chinese_word+0x40>
lea    -0x2(%r15),%r14d
nopl   0x0(%rax,%rax,1)
mov    %r15d,%ebp
lea    -0x2(%rbp),%r15d
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x20(%rsp,%r14,1)
mov    %r13,%rdi
call   1050 <exists_word@plt>
cmp    $0x5,%ebp
jb     1190 <process_chinese_word+0x40>
add    $0xfffffffffffffffe,%r14
test   %eax,%eax
je     1210 <process_chinese_word+0xc0>
jmp    1190 <process_chinese_word+0x40>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @process_chinese_word(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %9
store i32 0, i32* %7
br label %14
14: ; preds = %58, %3
%15 = load i32, i32* %7
%16 = load i32, i32* %9
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %69
18: ; preds = %14
%19 = load i32, i32* %9
%20 = load i32, i32* %7
%21 = sub nsw i32 %19, %20
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 10
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 10, i32* %8
br label %25
25: ; preds = %24, %18
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i32, i32* %8
%32 = call i32 @strncpy(i8* %26, i8* %30, i32 %31)
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %45, %25
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%38 = call i32 @exists_word(i8* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = load i32, i32* %8
%42 = icmp sgt i32 %41, 2
br label %43
43: ; preds = %40, %36
%44 = phi i1 [ false, %36 ], [ %42, %40 ]
br i1 %44, label %45, label %58
45: ; preds = %43
%46 = load i32, i32* %8
%47 = sub nsw i32 %46, 2
store i32 %47, i32* %8
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%49 = load i8*, i8** %6
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i32, i32* %8
%54 = call i32 @strncpy(i8* %48, i8* %52, i32 %53)
%55 = load i32, i32* %8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %56
store i8 0, i8* %57
br label %36
58: ; preds = %43
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%60 = call i32 @get_wordid(i8* %59, i32 1)
store i32 %60, i32* %10
%61 = load i32, i32* %10
%62 = load i32, i32* %5
%63 = load i32, i32* %7
%64 = add nsw i32 %62, %63
%65 = call i32 @put_word(i32 %61, i32 %64)
%66 = load i32, i32* %8
%67 = load i32, i32* %7
%68 = add nsw i32 %67, %66
store i32 %68, i32* %7
br label %14
69: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @process_chinese_word(i32 %0, i32 %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = tail call i32 @strlen(i8* %2)
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %5, 0
br i1 %7, label %8, label %39
8: ; preds = %3, %32
%9 = phi i32 [ %37, %32 ], [ 0, %3 ]
%10 = sub nsw i32 %5, %9
%11 = icmp slt i32 %10, 10
%12 = select i1 %11, i32 %10, i32 10
%13 = sext i32 %9 to i64
%14 = getelementptr inbounds i8, i8* %2, i64 %13
%15 = call i32 @strncpy(i8* %6, i8* %14, i32 %12)
%16 = sext i32 %12 to i64
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @exists_word(i8* %6)
%19 = icmp eq i32 %18, 0
%20 = icmp sgt i32 %12, 2
%21 = and i1 %20, %19
br i1 %21, label %22, label %32
22: ; preds = %8, %22
%23 = phi i32 [ %24, %22 ], [ %12, %8 ]
%24 = add nsw i32 %23, -2
%25 = call i32 @strncpy(i8* %6, i8* %14, i32 %24)
%26 = zext i32 %24 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 @exists_word(i8* %6)
%29 = icmp eq i32 %28, 0
%30 = icmp ugt i32 %23, 4
%31 = and i1 %30, %29
br i1 %31, label %22, label %32
32: ; preds = %22, %8
%33 = phi i32 [ %12, %8 ], [ %24, %22 ]
%34 = call i32 @get_wordid(i8* %6, i32 1)
%35 = add nsw i32 %9, %1
%36 = call i32 @put_word(i32 %34, i32 %35)
%37 = add nsw i32 %33, %9
%38 = icmp sgt i32 %5, %37
br i1 %38, label %8, label %39
39: ; preds = %32, %3
ret void
}