#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*/ compose_keys(unsigned int *, int *);
int /*<<< orphan*/ skip_spaces(char const **);
int strtokey(char const **);
int strtokeys(const char *kstr, unsigned int *keys, int max_keys) {
  int key, nb_keys;
  const char *p;
  p = kstr;
  nb_keys = 0;
  for (;;) {
    skip_spaces(&p);
    if (*p == '\0')
      break;
    key = strtokey(&p);
    keys[nb_keys++] = key;
    compose_keys(keys, &nb_keys);
    if (nb_keys >= max_keys)
      break;
  }
  return nb_keys;
}


x86 assembly (clang, -O0):
<strtokeys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <skip_spaces@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1170 <strtokeys+0x40>
jmp    11b7 <strtokeys+0x87>
lea    -0x28(%rbp),%rdi
call   1030 <strtokey@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <compose_keys@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11b2 <strtokeys+0x82>
jmp    11b7 <strtokeys+0x87>
jmp    1152 <strtokeys+0x22>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtokeys>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rbp
lea    0xc(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1050 <skip_spaces@plt>
mov    0x10(%rsp),%rax
cmpb   $0x0,(%rax)
je     119f <strtokeys+0x6f>
mov    %rbp,%rdi
call   1030 <strtokey@plt>
movslq 0xc(%rsp),%rcx
lea    0x1(%rcx),%edx
mov    %edx,0xc(%rsp)
mov    %eax,(%rbx,%rcx,4)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <compose_keys@plt>
mov    0xc(%rsp),%eax
cmp    %r14d,%eax
jl     1160 <strtokeys+0x30>
jmp    11a3 <strtokeys+0x73>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @strtokeys(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
store i8* %10, i8** %9
store i32 0, i32* %8
br label %11
11: ; preds = %32, %3
%12 = call i32 @skip_spaces(i8** %9)
%13 = load i8*, i8** %9
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
br label %33
18: ; preds = %11
%19 = call i32 @strtokey(i8** %9)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = load i32*, i32** %5
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i32, i32* %21, i64 %24
store i32 %20, i32* %25
%26 = load i32*, i32** %5
%27 = call i32 @compose_keys(i32* %26, i32* %8)
%28 = load i32, i32* %8
%29 = load i32, i32* %6
%30 = icmp sge i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %18
br label %33
32: ; preds = %18
br label %11
33: ; preds = %31, %17
%34 = load i32, i32* %8
ret i32 %34
}

LLVM IR (-O2):
define i32 @strtokeys(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast i32* %4 to i8*
%7 = bitcast i8** %5 to i8*
store i8* %0, i8** %5
store i32 0, i32* %4
br label %8
8: ; preds = %15, %3
%9 = call i32 @skip_spaces(i8** %5)
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = load i32, i32* %4
br label %24
15: ; preds = %8
%16 = call i32 @strtokey(i8** %5)
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds i32, i32* %1, i64 %19
store i32 %16, i32* %20
%21 = call i32 @compose_keys(i32* %1, i32* %4)
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, %2
br i1 %23, label %8, label %24
24: ; preds = %15, %13
%25 = phi i32 [ %14, %13 ], [ %22, %15 ]
ret i32 %25
}