#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*/ pair_list_push(int /*<<< orphan*/, unsigned char,
                                  unsigned char);
int parse_function_n(char const *);
int parse_int(char const *, int, int);
char *skip_token(char const *);
char *skip_whitespace(char const *);
int cmd_layerdef(const char *p) {
  int fn, n, ret = 3;
  unsigned char fn_combo = 0;
  p = skip_whitespace(p);
  for (p = skip_whitespace(p); *p; p = skip_token(p)) {
    fn = parse_function_n(p);
    if (fn == -9999)
      break;
    fn_combo |= (unsigned char)(1 << (fn - 1));
  }
  if (!fn_combo)
    goto ret;
  n = parse_int(p, 1, 255);
  if (n == -9999)
    goto ret;
  pair_list_push(0, fn_combo, (unsigned char)n);
  ret = 0;
ret:
  return ret;
}


x86 assembly (clang, -O0):
<cmd_layerdef>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x3,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <skip_whitespace@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <skip_whitespace@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d7 <cmd_layerdef+0x87>
mov    -0x8(%rbp),%rdi
call   1060 <parse_function_n@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffd8f1,-0xc(%rbp)
jne    11ac <cmd_layerdef+0x5c>
jmp    11d7 <cmd_layerdef+0x87>
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
movzbl %al,%ecx
movzbl -0x15(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <skip_token@plt>
mov    %rax,-0x8(%rbp)
jmp    1181 <cmd_layerdef+0x31>
cmpb   $0x0,-0x15(%rbp)
jne    11e6 <cmd_layerdef+0x96>
jmp    1228 <cmd_layerdef+0xd8>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0xff,%edx
call   1070 <parse_int@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffd8f1,-0x10(%rbp)
jne    120e <cmd_layerdef+0xbe>
jmp    1228 <cmd_layerdef+0xd8>
mov    -0x15(%rbp),%cl
mov    -0x10(%rbp),%eax
xor    %edi,%edi
movzbl %cl,%esi
movzbl %al,%edx
call   1030 <pair_list_push@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_layerdef>:
push   %rbp
push   %r14
push   %rbx
call   1040 <skip_whitespace@plt>
mov    %rax,%rdi
call   1040 <skip_whitespace@plt>
mov    $0x3,%r14d
cmpb   $0x0,(%rax)
je     11dc <cmd_layerdef+0x8c>
mov    %rax,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <parse_function_n@plt>
cmp    $0xffffd8f1,%eax
je     11ad <cmd_layerdef+0x5d>
add    $0xff,%al
mov    $0x1,%edx
mov    %eax,%ecx
shl    %cl,%edx
or     %dl,%bpl
mov    %rbx,%rdi
call   1050 <skip_token@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    1180 <cmd_layerdef+0x30>
test   %bpl,%bpl
je     11dc <cmd_layerdef+0x8c>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xff,%edx
call   1070 <parse_int@plt>
cmp    $0xffffd8f1,%eax
je     11dc <cmd_layerdef+0x8c>
movzbl %bpl,%esi
movzbl %al,%edx
xor    %r14d,%r14d
xor    %edi,%edi
call   1030 <pair_list_push@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cmd_layerdef(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %2
store i32 3, i32* %5
store i8 0, i8* %6
%7 = load i8*, i8** %2
%8 = call i8* @skip_whitespace(i8* %7)
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = call i8* @skip_whitespace(i8* %9)
store i8* %10, i8** %2
br label %11
11: ; preds = %31, %1
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = call i32 @parse_function_n(i8* %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, -9999
br i1 %19, label %20, label %21
20: ; preds = %15
br label %34
21: ; preds = %15
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, 1
%24 = shl i32 1, %23
%25 = trunc i32 %24 to i8
%26 = zext i8 %25 to i32
%27 = load i8, i8* %6
%28 = zext i8 %27 to i32
%29 = or i32 %28, %26
%30 = trunc i32 %29 to i8
store i8 %30, i8* %6
br label %31
31: ; preds = %21
%32 = load i8*, i8** %2
%33 = call i8* @skip_token(i8* %32)
store i8* %33, i8** %2
br label %11
34: ; preds = %20, %11
%35 = load i8, i8* %6
%36 = icmp ne i8 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %34
br label %49
38: ; preds = %34
%39 = load i8*, i8** %2
%40 = call i32 @parse_int(i8* %39, i32 1, i32 255)
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, -9999
br i1 %42, label %43, label %44
43: ; preds = %38
br label %49
44: ; preds = %38
%45 = load i8, i8* %6
%46 = load i32, i32* %4
%47 = trunc i32 %46 to i8
%48 = call i32 @pair_list_push(i32 0, i8 zeroext %45, i8 zeroext %47)
store i32 0, i32* %5
br label %49
49: ; preds = %44, %43, %37
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
define i32 @cmd_layerdef(i8* %0) {
%2 = tail call i8* @skip_whitespace(i8* %0)
%3 = tail call i8* @skip_whitespace(i8* %2)
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %29, label %6
6: ; preds = %1, %11
%7 = phi i8 [ %15, %11 ], [ 0, %1 ]
%8 = phi i8* [ %16, %11 ], [ %3, %1 ]
%9 = tail call i32 @parse_function_n(i8* %8)
%10 = icmp eq i32 %9, -9999
br i1 %10, label %19, label %11
11: ; preds = %6
%12 = add nsw i32 %9, -1
%13 = shl nuw i32 1, %12
%14 = trunc i32 %13 to i8
%15 = or i8 %7, %14
%16 = tail call i8* @skip_token(i8* %8)
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %6
19: ; preds = %11, %6
%20 = phi i8* [ %16, %11 ], [ %8, %6 ]
%21 = phi i8 [ %15, %11 ], [ %7, %6 ]
%22 = icmp eq i8 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = tail call i32 @parse_int(i8* %20, i32 1, i32 255)
%25 = icmp eq i32 %24, -9999
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = trunc i32 %24 to i8
%28 = tail call i32 @pair_list_push(i32 0, i8 zeroext %21, i8 zeroext %27)
br label %29
29: ; preds = %1, %23, %19, %26
%30 = phi i32 [ 3, %23 ], [ 0, %26 ], [ 3, %19 ], [ 3, %1 ]
ret i32 %30
}