#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 *piece_unknown(char *, char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
void test_piece_unknown(void) {
  char *string;
  char destination[16];
  char delimiter;
  string = "\"zero\"";
  printf("got string = (%s)\n", string);
  delimiter = 0;
  printf("should be zero: is (%s)\n",
         piece_unknown(destination, &delimiter, string, 0));
  string = "\"zero\",\"one\",\"two\"";
  printf("got string = (%s)\n", string);
  delimiter = 0;
  printf("should be one: is (%s)\n",
         piece_unknown(destination, &delimiter, string, 1));
  string = "\"zero\",\"one\",\"two\"";
  printf("got string = (%s)\n", string);
  delimiter = 0;
  printf("should be two: is (%s)\n",
         piece_unknown(destination, &delimiter, string, 2));
}


x86 assembly (clang, -O0):
<test_piece_unknown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x21(%rbp),%rsi
xor    %ecx,%ecx
call   1040 <piece_unknown@plt>
mov    %rax,%rsi
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
lea    0xec3(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x21(%rbp),%rsi
mov    $0x1,%ecx
call   1040 <piece_unknown@plt>
mov    %rax,%rsi
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
lea    0xe7f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x21(%rbp),%rsi
mov    $0x2,%ecx
call   1040 <piece_unknown@plt>
mov    %rax,%rsi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_piece_unknown>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xed5(%rip),%r14
lea    0xec7(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
movb   $0x0,0xf(%rsp)
lea    0x10(%rsp),%r12
lea    0xf(%rsp),%r15
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1040 <piece_unknown@plt>
lea    0xeb0(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xeba(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
movb   $0x0,0xf(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x1,%ecx
call   1040 <piece_unknown@plt>
lea    0xea3(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
movb   $0x0,0xf(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x2,%ecx
call   1040 <piece_unknown@plt>
lea    0xe89(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\22zero\22\00"
@.str.1 = [19 x i8] c"got string = (%s)\0A\00"
@.str.2 = [25 x i8] c"should be zero: is (%s)\0A\00"
@.str.3 = [19 x i8] c"\22zero\22,\22one\22,\22two\22\00"
@.str.4 = [24 x i8] c"should be one: is (%s)\0A\00"
@.str.5 = [24 x i8] c"should be two: is (%s)\0A\00"
define void @test_piece_unknown() {
%1 = alloca i8*
%2 = alloca [16 x i8]
%3 = alloca i8
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %1
%4 = load i8*, i8** %1
%5 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %4)
store i8 0, i8* %3
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%7 = load i8*, i8** %1
%8 = call i8* @piece_unknown(i8* %6, i8* %3, i8* %7, i32 0)
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %8)
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8** %1
%10 = load i8*, i8** %1
%11 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %10)
store i8 0, i8* %3
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%13 = load i8*, i8** %1
%14 = call i8* @piece_unknown(i8* %12, i8* %3, i8* %13, i32 1)
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %14)
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8** %1
%16 = load i8*, i8** %1
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i8 0, i8* %3
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%19 = load i8*, i8** %1
%20 = call i8* @piece_unknown(i8* %18, i8* %3, i8* %19, i32 2)
%21 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %20)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"\22zero\22\00"
@.str.1 = [19 x i8] c"got string = (%s)\0A\00"
@.str.2 = [25 x i8] c"should be zero: is (%s)\0A\00"
@.str.3 = [19 x i8] c"\22zero\22,\22one\22,\22two\22\00"
@.str.4 = [24 x i8] c"should be one: is (%s)\0A\00"
@.str.5 = [24 x i8] c"should be two: is (%s)\0A\00"
define void @test_piece_unknown() {
%1 = alloca [16 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %2
%5 = call i8* @piece_unknown(i8* %3, i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i8 0, i8* %2
%8 = call i8* @piece_unknown(i8* %3, i8* %2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 1)
%9 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i8 0, i8* %2
%11 = call i8* @piece_unknown(i8* %3, i8* %2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 2)
%12 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %11)
ret void
}