#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 */
char *NextAmpersand(char const *);
int /*<<< orphan*/ diagnostics(int, char *, char const *, char const *);
int /*<<< orphan*/ free(char *);
char *my_strndup(char const *, size_t);
char *strdup_noendblanks(char const *);
void TabularGetCell(const char *cell_start, char **cell, char **next_cell) {
  char *cell_end, *dup;
  *cell = NULL;
  *next_cell = NULL;
  if (cell_start == NULL)
    return;
  diagnostics(5, "TabularGetCell %p start='%s'", cell_start, cell_start);
  cell_end = NextAmpersand(cell_start);
  if (*cell_end != '&') {
    *cell = strdup_noendblanks(cell_start);
    return;
  }
  *next_cell = cell_end + 1;
  dup = my_strndup(cell_start, (size_t)(cell_end - cell_start));
  *cell = strdup_noendblanks(dup);
  free(dup);
}


x86 assembly (clang, -O0):
<TabularGetCell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x8(%rbp)
jne    118a <TabularGetCell+0x3a>
jmp    121b <TabularGetCell+0xcb>
mov    -0x8(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x5,%edi
lea    0xe62(%rip),%rsi
call   1050 <diagnostics@plt>
mov    -0x8(%rbp),%rdi
call   1070 <NextAmpersand@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
je     11d8 <TabularGetCell+0x88>
mov    -0x8(%rbp),%rdi
call   1040 <strdup_noendblanks@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    121b <TabularGetCell+0xcb>
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rax
sub    %rax,%rsi
call   1060 <my_strndup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strdup_noendblanks@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TabularGetCell>:
push   %r15
push   %r14
push   %rbx
movq   $0x0,(%rsi)
movq   $0x0,(%rdx)
test   %rdi,%rdi
je     11d0 <TabularGetCell+0x80>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe88(%rip),%rsi
mov    $0x5,%edi
mov    %rbx,%rdx
mov    %rbx,%rcx
call   1050 <diagnostics@plt>
mov    %rbx,%rdi
call   1070 <NextAmpersand@plt>
cmpb   $0x26,(%rax)
jne    11c5 <TabularGetCell+0x75>
lea    0x1(%rax),%rcx
mov    %rcx,(%r15)
sub    %rbx,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <my_strndup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strdup_noendblanks@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    %rbx,%rdi
call   1040 <strdup_noendblanks@plt>
mov    %rax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"TabularGetCell %p start='%s'\00"
define void @TabularGetCell(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%9 = load i8**, i8*** %5
store i8* null, i8** %9
%10 = load i8**, i8*** %6
store i8* null, i8** %10
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
br label %44
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = load i8*, i8** %4
%17 = call i32 @diagnostics(i32 5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
%18 = load i8*, i8** %4
%19 = call i8* @NextAmpersand(i8* %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 38
br i1 %23, label %24, label %28
24: ; preds = %14
%25 = load i8*, i8** %4
%26 = call i8* @strdup_noendblanks(i8* %25)
%27 = load i8**, i8*** %5
store i8* %26, i8** %27
br label %44
28: ; preds = %14
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8**, i8*** %6
store i8* %30, i8** %31
%32 = load i8*, i8** %4
%33 = load i8*, i8** %7
%34 = load i8*, i8** %4
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = call i8* @my_strndup(i8* %32, i64 %37)
store i8* %38, i8** %8
%39 = load i8*, i8** %8
%40 = call i8* @strdup_noendblanks(i8* %39)
%41 = load i8**, i8*** %5
store i8* %40, i8** %41
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
br label %44
44: ; preds = %28, %24, %13
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"TabularGetCell %p start='%s'\00"
define void @TabularGetCell(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
store i8* null, i8** %1
store i8* null, i8** %2
%4 = icmp eq i8* %0, null
br i1 %4, label %20, label %5
5: ; preds = %3
%6 = tail call i32 @diagnostics(i32 5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %0)
%7 = tail call i8* @NextAmpersand(i8* %0)
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 38
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i8* @strdup_noendblanks(i8* %0)
store i8* %11, i8** %1
br label %20
12: ; preds = %5
%13 = getelementptr inbounds i8, i8* %7, i64 1
store i8* %13, i8** %2
%14 = ptrtoint i8* %7 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = tail call i8* @my_strndup(i8* %0, i64 %16)
%18 = tail call i8* @strdup_noendblanks(i8* %17)
store i8* %18, i8** %1
%19 = tail call i32 @free(i8* %17)
br label %20
20: ; preds = %3, %12, %10
ret void
}