#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 EOF;
int getchar();
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int strindex(char *, char);
char **strspt(char *, char);
int /*<<< orphan*/ text_info(char *);
int /*<<< orphan*/ text_reverse(char *);
void test_writer() {
  int i;
  char **split = strspt("123|asd|456|zxc", '|');
  for (i = 0; *(split + i) != NULL; i++)
    printf("{%s}\n", *(split + i));
  int read;
  i = 0;
  char *string = malloc(sizeof(char));
  while ((read = getchar()) != EOF) {
    string[i++] = read;
    if (read == '\n')
      printf(": ");
    else if (read == '.') {
      string[i] = '\0';
      break;
    }
  }
  text_info(string);
  text_reverse(string);
  printf("End at index %d\n", strindex(string, '.'));
  text_reverse(string);
}


x86 assembly (clang, -O0):
<test_writer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
mov    $0x7c,%esi
call   1080 <strspt@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11cf <test_writer+0x5f>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <test_writer+0x24>
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%eax
je     1259 <test_writer+0xe9>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x4(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x4(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0xa,-0x14(%rbp)
jne    1234 <test_writer+0xc4>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1254 <test_writer+0xe4>
cmpl   $0x2e,-0x14(%rbp)
jne    124f <test_writer+0xdf>
mov    -0x20(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1259 <test_writer+0xe9>
jmp    1254 <test_writer+0xe4>
jmp    11e4 <test_writer+0x74>
mov    -0x20(%rbp),%rdi
call   1040 <text_info@plt>
mov    -0x20(%rbp),%rdi
call   1090 <text_reverse@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1070 <strindex@plt>
mov    %eax,%esi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <text_reverse@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_writer>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe81(%rip),%rdi
mov    $0x7c,%esi
call   1080 <strspt@plt>
mov    (%rax),%rsi
test   %rsi,%rsi
je     11b6 <test_writer+0x46>
mov    %rax,%rbx
add    $0x8,%rbx
lea    0xe71(%rip),%r14
nop
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11a0 <test_writer+0x30>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e17(%rip),%r15
cmp    (%r15),%eax
je     1220 <test_writer+0xb0>
mov    $0x1,%ebx
lea    0xe34(%rip),%r14
jmp    120a <test_writer+0x9a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0x1,%rbx
cmp    (%r15),%eax
je     1220 <test_writer+0xb0>
mov    %al,-0x1(%r12,%rbx,1)
cmp    $0xa,%eax
je     11f0 <test_writer+0x80>
cmp    $0x2e,%eax
jne    11fa <test_writer+0x8a>
mov    %ebx,%eax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
call   1040 <text_info@plt>
mov    %r12,%rdi
call   1090 <text_reverse@plt>
mov    %r12,%rdi
mov    $0x2e,%esi
call   1070 <strindex@plt>
lea    0xdd5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1090 <text_reverse@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"123|asd|456|zxc\00"
@.str.1 = [6 x i8] c"{%s}\0A\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c": \00"
@.str.3 = [17 x i8] c"End at index %d\0A\00"
define void @test_writer() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i8*
%5 = call i8** @strspt(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext 124)
store i8** %5, i8*** %2
store i32 0, i32* %1
br label %6
6: ; preds = %20, %0
%7 = load i8**, i8*** %2
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8*, i8** %7, i64 %9
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %23
13: ; preds = %6
%14 = load i8**, i8*** %2
%15 = load i32, i32* %1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %13
%21 = load i32, i32* %1
%22 = add nsw i32 %21, 1
store i32 %22, i32* %1
br label %6
23: ; preds = %6
store i32 0, i32* %1
%24 = call i8* @malloc(i32 1)
store i8* %24, i8** %4
br label %25
25: ; preds = %50, %23
%26 = call i32 (...) @getchar()
store i32 %26, i32* %3
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %51
29: ; preds = %25
%30 = load i32, i32* %3
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %4
%33 = load i32, i32* %1
%34 = add nsw i32 %33, 1
store i32 %34, i32* %1
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 %31, i8* %36
%37 = load i32, i32* %3
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %41
39: ; preds = %29
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %50
41: ; preds = %29
%42 = load i32, i32* %3
%43 = icmp eq i32 %42, 46
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i8*, i8** %4
%46 = load i32, i32* %1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
br label %51
49: ; preds = %41
br label %50
50: ; preds = %49, %39
br label %25
51: ; preds = %44, %25
%52 = load i8*, i8** %4
%53 = call i32 @text_info(i8* %52)
%54 = load i8*, i8** %4
%55 = call i32 @text_reverse(i8* %54)
%56 = load i8*, i8** %4
%57 = call i32 @strindex(i8* %56, i8 signext 46)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = load i8*, i8** %4
%60 = call i32 @text_reverse(i8* %59)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"123|asd|456|zxc\00"
@.str.1 = [6 x i8] c"{%s}\0A\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c": \00"
@.str.3 = [17 x i8] c"End at index %d\0A\00"
define void @test_writer() {
%1 = tail call i8** @strspt(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext 124)
%2 = load i8*, i8** %1
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %0, %4
%5 = phi i64 [ %8, %4 ], [ 0, %0 ]
%6 = phi i8* [ %10, %4 ], [ %2, %0 ]
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = add nuw i64 %5, 1
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %4
12: ; preds = %4, %0
%13 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %32, label %17
17: ; preds = %12, %28
%18 = phi i64 [ %21, %28 ], [ 0, %12 ]
%19 = phi i32 [ %29, %28 ], [ %14, %12 ]
%20 = trunc i32 %19 to i8
%21 = add nuw i64 %18, 1
%22 = getelementptr inbounds i8, i8* %13, i64 %18
store i8 %20, i8* %22
switch i32 %19, label %28 [
i32 10, label %23
i32 46, label %25
]
23: ; preds = %17
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %28
25: ; preds = %17
%26 = and i64 %21, 4294967295
%27 = getelementptr inbounds i8, i8* %13, i64 %26
store i8 0, i8* %27
br label %32
28: ; preds = %17, %23
%29 = tail call i32 (...) @getchar()
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %17
32: ; preds = %28, %12, %25
%33 = tail call i32 @text_info(i8* %13)
%34 = tail call i32 @text_reverse(i8* %13)
%35 = tail call i32 @strindex(i8* %13, i8 signext 46)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = tail call i32 @text_reverse(i8* %13)
ret void
}