#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);
char *method(char *message) {
  char *buffer;
  char *bufferptr;
  buffer = malloc(sizeof(char) * 7);
  if (buffer == NULL) {
    return NULL;
  }
  bufferptr = buffer;
  while (*message != ' ' && *message != '\0') {
    *buffer++ = *message++;
  }
  *buffer = '\0';
  return bufferptr;
}


x86 assembly (clang, -O0):
<method>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x7,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1142 <method+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <method+0xa5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x21(%rbp)
je     116f <method+0x5f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117f <method+0x6f>
jmp    11a6 <method+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    114a <method+0x3a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<method>:
push   %rbx
mov    %rdi,%rbx
mov    $0x7,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1146 <method+0x36>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx,%rcx,1),%edx
test   $0xdf,%dl
je     1142 <method+0x32>
mov    %dl,(%rax,%rcx,1)
add    $0x1,%rcx
jmp    1130 <method+0x20>
movb   $0x0,(%rax,%rcx,1)
pop    %rbx
ret

LLVM IR (-O0):
define i8* @method(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = call i8* @malloc(i32 7)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %33
10: ; preds = %1
%11 = load i8*, i8** %4
store i8* %11, i8** %5
br label %12
12: ; preds = %24, %10
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 32
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %17, %12
%23 = phi i1 [ false, %12 ], [ %21, %17 ]
br i1 %23, label %24, label %30
24: ; preds = %22
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
%27 = load i8, i8* %25
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
store i8 %27, i8* %28
br label %12
30: ; preds = %22
%31 = load i8*, i8** %4
store i8 0, i8* %31
%32 = load i8*, i8** %5
store i8* %32, i8** %2
br label %33
33: ; preds = %30, %9
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
define noalias i8* @method(i8* nocapture %0) {
%2 = tail call dereferenceable_or_null(7) i8* @malloc(i32 7)
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1, %8
%5 = phi i8* [ %9, %8 ], [ %0, %1 ]
%6 = phi i8* [ %10, %8 ], [ %2, %1 ]
%7 = load i8, i8* %5
switch i8 %7, label %8 [
i8 32, label %11
i8 0, label %11
]
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %7, i8* %6
br label %4
11: ; preds = %4, %4
store i8 0, i8* %6
br label %12
12: ; preds = %1, %11
ret i8* %2
}