#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*/ copy_str(char *, int, char const *);
int /*<<< orphan*/ status_bar_error(char *);
char *strchr(char const *, char);
int strcspn(char const *, char *);
char *strpbrk(char const *, char *);
int parse_apropos_line(const char line[], char section[], size_t section_len,
                       char topic[], size_t topic_len) {
  const char *sec_l, *sec_r;
  const char *sep;
  sec_l = strchr(line, '(');
  if (sec_l == NULL) {
    status_bar_error("Failed to find section number.");
    return 1;
  }
  sec_r = sec_l + 1 + strcspn(sec_l + 1, " \t()");
  if (sec_r == sec_l + 1 || *sec_r != ')') {
    status_bar_error("Wrong section number format.");
    return 1;
  }
  sep = strpbrk(line, " (");
  if (section_len == 0 || section_len - 1 < (size_t)(sec_r - (sec_l + 1)) ||
      topic_len == 0 || topic_len - 1 < (size_t)(sep - line)) {
    status_bar_error("Internal buffer is too small.");
    return 1;
  }
  copy_str(topic, sep - line + 1, line);
  copy_str(section, sec_r - (sec_l + 1) + 1, sec_l + 1);
  return 0;
}


x86 assembly (clang, -O0):
<parse_apropos_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x28,%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11a1 <parse_apropos_line+0x51>
lea    0xe70(%rip),%rdi
call   1060 <status_bar_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d7 <parse_apropos_line+0x187>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
lea    0xe63(%rip),%rsi
call   1040 <strcspn@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
je     11f6 <parse_apropos_line+0xa6>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     120e <parse_apropos_line+0xbe>
lea    0xe27(%rip),%rdi
call   1060 <status_bar_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d7 <parse_apropos_line+0x187>
mov    -0x10(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1070 <strpbrk@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1274 <parse_apropos_line+0x124>
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%rdx
add    $0x1,%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jb     1274 <parse_apropos_line+0x124>
cmpq   $0x0,-0x30(%rbp)
je     1274 <parse_apropos_line+0x124>
mov    -0x30(%rbp),%rax
sub    $0x1,%rax
mov    -0x48(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jae    128c <parse_apropos_line+0x13c>
lea    0xdc9(%rip),%rdi
call   1060 <status_bar_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d7 <parse_apropos_line+0x187>
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1050 <copy_str@plt>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%esi
mov    -0x38(%rbp),%rdx
add    $0x1,%rdx
call   1050 <copy_str@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_apropos_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r13
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r12
mov    $0x28,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11ec <parse_apropos_line+0x9c>
mov    %rax,%rbx
mov    %r15,0x8(%rsp)
mov    %rbp,0x10(%rsp)
add    $0x1,%rbx
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcspn@plt>
test   %eax,%eax
je     11e3 <parse_apropos_line+0x93>
mov    %eax,%ebp
movslq %eax,%r15
cmpb   $0x29,(%rbx,%r15,1)
jne    11e3 <parse_apropos_line+0x93>
lea    0xe8e(%rip),%rsi
mov    %r12,%rdi
call   1070 <strpbrk@plt>
test   %r14,%r14
je     11da <parse_apropos_line+0x8a>
test   %r13,%r13
je     11da <parse_apropos_line+0x8a>
add    $0xffffffffffffffff,%r14
cmp    %r15,%r14
jb     11da <parse_apropos_line+0x8a>
add    $0xffffffffffffffff,%r13
sub    %r12,%rax
cmp    %rax,%r13
jae    120c <parse_apropos_line+0xbc>
lea    0xe63(%rip),%rdi
jmp    11f3 <parse_apropos_line+0xa3>
lea    0xe3a(%rip),%rdi
jmp    11f3 <parse_apropos_line+0xa3>
lea    0xe0d(%rip),%rdi
call   1060 <status_bar_error@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%eax
mov    0x8(%rsp),%rdi
mov    %eax,%esi
mov    %r12,%rdx
call   1050 <copy_str@plt>
add    $0x1,%ebp
mov    0x10(%rsp),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1050 <copy_str@plt>
xor    %eax,%eax
jmp    11fd <parse_apropos_line+0xad>

LLVM IR (-O0):
@.str = [31 x i8] c"Failed to find section number.\00"
@.str.1 = [5 x i8] c" \09()\00"
@.str.2 = [29 x i8] c"Wrong section number format.\00"
@.str.3 = [3 x i8] c" (\00"
@.str.4 = [30 x i8] c"Internal buffer is too small.\00"
define i32 @parse_apropos_line(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%15 = load i8*, i8** %7
%16 = call i8* @strchr(i8* %15, i8 signext 40)
store i8* %16, i8** %12
%17 = load i8*, i8** %12
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %5
%20 = call i32 @status_bar_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %92
21: ; preds = %5
%22 = load i8*, i8** %12
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8*, i8** %12
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i32 @strcspn(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
store i8* %28, i8** %13
%29 = load i8*, i8** %13
%30 = load i8*, i8** %12
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = icmp eq i8* %29, %31
br i1 %32, label %38, label %33
33: ; preds = %21
%34 = load i8*, i8** %13
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 41
br i1 %37, label %38, label %40
38: ; preds = %33, %21
%39 = call i32 @status_bar_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %92
40: ; preds = %33
%41 = load i8*, i8** %7
%42 = call i8* @strpbrk(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %42, i8** %14
%43 = load i64, i64* %9
%44 = icmp eq i64 %43, 0
br i1 %44, label %67, label %45
45: ; preds = %40
%46 = load i64, i64* %9
%47 = sub i64 %46, 1
%48 = load i8*, i8** %13
%49 = load i8*, i8** %12
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = ptrtoint i8* %48 to i64
%52 = ptrtoint i8* %50 to i64
%53 = sub i64 %51, %52
%54 = icmp ult i64 %47, %53
br i1 %54, label %67, label %55
55: ; preds = %45
%56 = load i64, i64* %11
%57 = icmp eq i64 %56, 0
br i1 %57, label %67, label %58
58: ; preds = %55
%59 = load i64, i64* %11
%60 = sub i64 %59, 1
%61 = load i8*, i8** %14
%62 = load i8*, i8** %7
%63 = ptrtoint i8* %61 to i64
%64 = ptrtoint i8* %62 to i64
%65 = sub i64 %63, %64
%66 = icmp ult i64 %60, %65
br i1 %66, label %67, label %69
67: ; preds = %58, %55, %45, %40
%68 = call i32 @status_bar_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %6
br label %92
69: ; preds = %58
%70 = load i8*, i8** %10
%71 = load i8*, i8** %14
%72 = load i8*, i8** %7
%73 = ptrtoint i8* %71 to i64
%74 = ptrtoint i8* %72 to i64
%75 = sub i64 %73, %74
%76 = add nsw i64 %75, 1
%77 = trunc i64 %76 to i32
%78 = load i8*, i8** %7
%79 = call i32 @copy_str(i8* %70, i32 %77, i8* %78)
%80 = load i8*, i8** %8
%81 = load i8*, i8** %13
%82 = load i8*, i8** %12
%83 = getelementptr inbounds i8, i8* %82, i64 1
%84 = ptrtoint i8* %81 to i64
%85 = ptrtoint i8* %83 to i64
%86 = sub i64 %84, %85
%87 = add nsw i64 %86, 1
%88 = trunc i64 %87 to i32
%89 = load i8*, i8** %12
%90 = getelementptr inbounds i8, i8* %89, i64 1
%91 = call i32 @copy_str(i8* %80, i32 %88, i8* %90)
store i32 0, i32* %6
br label %92
92: ; preds = %69, %67, %38, %19
%93 = load i32, i32* %6
ret i32 %93
}

LLVM IR (-O2):
@.str = [31 x i8] c"Failed to find section number.\00"
@.str.1 = [5 x i8] c" \09()\00"
@.str.2 = [29 x i8] c"Wrong section number format.\00"
@.str.3 = [3 x i8] c" (\00"
@.str.4 = [30 x i8] c"Internal buffer is too small.\00"
define i32 @parse_apropos_line(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 40)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @status_bar_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %43
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = tail call i32 @strcspn(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = sext i32 %12 to i64
%14 = icmp eq i32 %12, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = getelementptr inbounds i8, i8* %11, i64 %13
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 41
br i1 %18, label %21, label %19
19: ; preds = %15, %10
%20 = tail call i32 @status_bar_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %43
21: ; preds = %15
%22 = tail call i8* @strpbrk(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %2, 0
br i1 %23, label %35, label %24
24: ; preds = %21
%25 = add i64 %2, -1
%26 = icmp ult i64 %25, %13
%27 = icmp eq i64 %4, 0
%28 = or i1 %27, %26
br i1 %28, label %35, label %29
29: ; preds = %24
%30 = add i64 %4, -1
%31 = ptrtoint i8* %22 to i64
%32 = ptrtoint i8* %0 to i64
%33 = sub i64 %31, %32
%34 = icmp ult i64 %30, %33
br i1 %34, label %35, label %37
35: ; preds = %29, %24, %21
%36 = tail call i32 @status_bar_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %43
37: ; preds = %29
%38 = trunc i64 %33 to i32
%39 = add i32 %38, 1
%40 = tail call i32 @copy_str(i8* %3, i32 %39, i8* %0)
%41 = add i32 %12, 1
%42 = tail call i32 @copy_str(i8* %1, i32 %41, i8* %11)
br label %43
43: ; preds = %37, %35, %19, %8
%44 = phi i32 [ 1, %8 ], [ 1, %19 ], [ 1, %35 ], [ 0, %37 ]
ret i32 %44
}