#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 */
long parse_single_constant(char *, char **);
char *tokenize(char **, char *);
long int parse_constant(char *constant_str, char **endptr) {
  long int value = 0;
  char *group, *lastpos = constant_str;
  char *original_constant_str = constant_str;
  while ((group = tokenize(&constant_str, "|")) != NULL) {
    char *end = group;
    value |= parse_single_constant(group, &end);
    if (end == group) {
      lastpos = original_constant_str;
      value = 0;
      break;
    }
    lastpos = end;
  }
  if (endptr)
    *endptr = lastpos;
  return value;
}


x86 assembly (clang, -O0):
<parse_constant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x8(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1030 <tokenize@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11b3 <parse_constant+0x93>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <parse_single_constant@plt>
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    11a6 <parse_constant+0x86>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
jmp    11b3 <parse_constant+0x93>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1148 <parse_constant+0x28>
cmpq   $0x0,-0x10(%rbp)
je     11c9 <parse_constant+0xa9>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_constant>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rdi,0x10(%rsp)
lea    0xec0(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <tokenize@plt>
test   %rax,%rax
mov    %rbx,0x20(%rsp)
je     11a7 <parse_constant+0x87>
mov    %rax,%r14
mov    %r15,0x18(%rsp)
lea    0x8(%rsp),%r12
lea    0xe98(%rip),%r13
lea    0x10(%rsp),%rbp
xor    %ebx,%ebx
nop
mov    %r14,0x8(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <parse_single_constant@plt>
mov    0x8(%rsp),%r15
cmp    %r14,%r15
je     11a2 <parse_constant+0x82>
or     %rax,%rbx
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <tokenize@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1170 <parse_constant+0x50>
jmp    11a9 <parse_constant+0x89>
mov    0x18(%rsp),%r15
xor    %ebx,%ebx
mov    0x20(%rsp),%rax
test   %rax,%rax
je     11b6 <parse_constant+0x96>
mov    %r15,(%rax)
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"|\00"
define i64 @parse_constant(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i64 0, i64* %5
%10 = load i8*, i8** %3
store i8* %10, i8** %7
%11 = load i8*, i8** %3
store i8* %11, i8** %8
br label %12
12: ; preds = %26, %2
%13 = call i8* @tokenize(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %28
15: ; preds = %12
%16 = load i8*, i8** %6
store i8* %16, i8** %9
%17 = load i8*, i8** %6
%18 = call i64 @parse_single_constant(i8* %17, i8** %9)
%19 = load i64, i64* %5
%20 = or i64 %19, %18
store i64 %20, i64* %5
%21 = load i8*, i8** %9
%22 = load i8*, i8** %6
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = load i8*, i8** %8
store i8* %25, i8** %7
store i64 0, i64* %5
br label %28
26: ; preds = %15
%27 = load i8*, i8** %9
store i8* %27, i8** %7
br label %12
28: ; preds = %24, %12
%29 = load i8**, i8*** %4
%30 = icmp ne i8** %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = load i8**, i8*** %4
store i8* %32, i8** %33
br label %34
34: ; preds = %31, %28
%35 = load i64, i64* %5
ret i64 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"|\00"
define i64 @parse_constant(i8* %0, i8** writeonly %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = bitcast i8** %4 to i8*
%6 = call i8* @tokenize(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %18, label %11
8: ; preds = %11
%9 = call i8* @tokenize(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %2, %8
%12 = phi i8* [ %9, %8 ], [ %6, %2 ]
%13 = phi i64 [ %17, %8 ], [ 0, %2 ]
store i8* %12, i8** %4
%14 = call i64 @parse_single_constant(i8* %12, i8** %4)
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, %12
%17 = or i64 %14, %13
br i1 %16, label %18, label %8
18: ; preds = %8, %11, %2
%19 = phi i8* [ %0, %2 ], [ %0, %11 ], [ %15, %8 ]
%20 = phi i64 [ 0, %2 ], [ 0, %11 ], [ %17, %8 ]
%21 = icmp eq i8** %1, null
br i1 %21, label %23, label %22
22: ; preds = %18
store i8* %19, i8** %1
br label %23
23: ; preds = %22, %18
ret i64 %20
}