#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 */
scalar_t__ isdigit(char);
int strlen(char *);
char *strtok(char *, char *);
int /*<<< orphan*/ valid_layout_or_variant(char *);
char *get_layout(char *syms, int grp_num) {
  char *tok, *layout;
  int grp;
  layout = NULL;
  tok = strtok(syms, "+:");
  for (grp = 0; tok && grp <= grp_num; tok = strtok(NULL, "+:")) {
    if (!valid_layout_or_variant(tok)) {
      continue;
    } else if (strlen(tok) == 1 && isdigit(tok[0])) {
      continue;
    }
    layout = tok;
    grp++;
  }
  return layout;
}


x86 assembly (clang, -O0):
<get_layout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x25(%rbp)
je     118e <get_layout+0x4e>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
setle  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    119e <get_layout+0x5e>
jmp    1211 <get_layout+0xd1>
mov    -0x18(%rbp),%rdi
call   1050 <valid_layout_or_variant@plt>
cmp    $0x0,%eax
jne    11b5 <get_layout+0x75>
jmp    11f8 <get_layout+0xb8>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11e2 <get_layout+0xa2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e2 <get_layout+0xa2>
jmp    11f8 <get_layout+0xb8>
jmp    11e7 <get_layout+0xa7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdfd(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1172 <get_layout+0x32>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_layout>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
lea    0xeae(%rip),%rsi
call   1060 <strtok@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11c3 <get_layout+0x83>
test   %r12d,%r12d
js     11c3 <get_layout+0x83>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xe90(%rip),%r15
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <valid_layout_or_variant@plt>
test   %eax,%eax
je     11ac <get_layout+0x6c>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11a6 <get_layout+0x66>
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    11ac <get_layout+0x6c>
add    $0x1,%ebp
mov    %rbx,%r14
xor    %edi,%edi
mov    %r15,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11c3 <get_layout+0x83>
mov    %rax,%rbx
cmp    %r12d,%ebp
jle    1180 <get_layout+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"+:\00"
define i8* @get_layout(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %6
%8 = load i8*, i8** %3
%9 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
store i32 0, i32* %7
br label %10
10: ; preds = %40, %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* %7
%15 = load i32, i32* %4
%16 = icmp sle i32 %14, %15
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ false, %10 ], [ %16, %13 ]
br i1 %18, label %19, label %42
19: ; preds = %17
%20 = load i8*, i8** %5
%21 = call i32 @valid_layout_or_variant(i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %19
br label %40
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = call i32 @strlen(i8* %25)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = call i64 @isdigit(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
br label %40
35: ; preds = %28, %24
br label %36
36: ; preds = %35
%37 = load i8*, i8** %5
store i8* %37, i8** %6
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %40
40: ; preds = %36, %34, %23
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %41, i8** %5
br label %10
42: ; preds = %17
%43 = load i8*, i8** %6
ret i8* %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"+:\00"
define i8* @get_layout(i8* %0, i32 %1) {
%3 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i8* %3, null
%5 = icmp sgt i32 %1, -1
%6 = and i1 %4, %5
br i1 %6, label %7, label %29
7: ; preds = %2, %22
%8 = phi i32 [ %24, %22 ], [ 0, %2 ]
%9 = phi i8* [ %23, %22 ], [ null, %2 ]
%10 = phi i8* [ %25, %22 ], [ %3, %2 ]
%11 = tail call i32 @valid_layout_or_variant(i8* %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %7
%14 = tail call i32 @strlen(i8* %10)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8, i8* %10
%18 = tail call i64 @isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %13, %16
%21 = add nsw i32 %8, 1
br label %22
22: ; preds = %16, %7, %20
%23 = phi i8* [ %9, %16 ], [ %10, %20 ], [ %9, %7 ]
%24 = phi i32 [ %8, %16 ], [ %21, %20 ], [ %8, %7 ]
%25 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%26 = icmp ne i8* %25, null
%27 = icmp sle i32 %24, %1
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %7, label %29
29: ; preds = %22, %2
%30 = phi i8* [ null, %2 ], [ %23, %22 ]
ret i8* %30
}