#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 *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
char *getWordFromTaggedString(char *str) {
  char *result = malloc(sizeof(char) * 256);
  char cToStr[2];
  cToStr[1] = '\0';
  int i = 0;
  while (str[i] != '_') {
    cToStr[0] = str[i];
    strcat(result, cToStr);
    i++;
  }
  return result;
}


x86 assembly (clang, -O0):
<getWordFromTaggedString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x100,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
je     1183 <getWordFromTaggedString+0x63>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x12(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <getWordFromTaggedString+0x25>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getWordFromTaggedString>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x100,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
movb   $0x0,0xf(%rsp)
mov    (%rbx),%al
cmp    $0x5f,%al
je     116a <getWordFromTaggedString+0x4a>
add    $0x1,%rbx
lea    0xe(%rsp),%r15
nopl   (%rax)
mov    %al,0xe(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
cmp    $0x5f,%al
jne    1150 <getWordFromTaggedString+0x30>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @getWordFromTaggedString(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [2 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i8* @malloc(i32 256)
store i8* %6, i8** %3
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %7
store i32 0, i32* %5
br label %8
8: ; preds = %16, %1
%9 = load i8*, i8** %2
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 95
br i1 %15, label %16, label %28
16: ; preds = %8
%17 = load i8*, i8** %2
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %21, i8* %22
%23 = load i8*, i8** %3
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %8
28: ; preds = %8
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define i8* @getWordFromTaggedString(i8* nocapture %0) {
%2 = alloca [2 x i8]
%3 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 0, i8* %5
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 95
br i1 %7, label %16, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %12, %8 ], [ 0, %1 ]
%10 = phi i8 [ %14, %8 ], [ %6, %1 ]
store i8 %10, i8* %4
%11 = call i32 @strcat(i8* %3, i8* %4)
%12 = add nuw i64 %9, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 95
br i1 %15, label %16, label %8
16: ; preds = %8, %1
ret i8* %3
}