#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ strlcpy(char *, char const *, int);
char toupper(char);
const char *str_filter(const char *str) {
  static char buf[1024];
  char *s;
  if (str == NULL || *str == '\0')
    return str;
  strlcpy(buf, str, sizeof(buf));
  s = buf;
  do {
    *s = toupper(*s);
  } while (*s++);
  return buf;
}


x86 assembly (clang, -O0):
<str_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1147 <str_filter+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1154 <str_filter+0x34>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <str_filter+0x8b>
mov    -0x10(%rbp),%rsi
lea    0x2ee1(%rip),%rdi
mov    $0x400,%edx
call   1040 <strlcpy@plt>
lea    0x2ed0(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,(%rax)
jne    1174 <str_filter+0x54>
lea    0x2e99(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_filter>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1167 <str_filter+0x47>
mov    %rdi,%rax
cmpb   $0x0,(%rdi)
je     1169 <str_filter+0x49>
lea    0x2f08(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x400,%edx
call   1040 <strlcpy@plt>
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
test   %al,%al
jne    1150 <str_filter+0x30>
mov    %r14,%rax
jmp    1169 <str_filter+0x49>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@str_filter.buf = internal global [1024 x i8] zeroinitializer
define i8* @str_filter(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7, %1
%13 = load i8*, i8** %3
store i8* %13, i8** %2
br label %28
14: ; preds = %7
%15 = load i8*, i8** %3
%16 = call i32 @strlcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_filter.buf, i64 0, i64 0), i8* %15, i32 1024)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_filter.buf, i64 0, i64 0), i8** %4
br label %17
17: ; preds = %22, %14
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = call signext i8 @toupper(i8 signext %19)
%21 = load i8*, i8** %4
store i8 %20, i8* %21
br label %22
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
%25 = load i8, i8* %23
%26 = icmp ne i8 %25, 0
br i1 %26, label %17, label %27
27: ; preds = %22
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_filter.buf, i64 0, i64 0), i8** %2
br label %28
28: ; preds = %27, %12
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@str_filter.buf = internal global [1024 x i8] zeroinitializer
define i8* @str_filter(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = tail call i32 @strlcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_filter.buf, i64 0, i64 0), i8* %0, i32 1024)
br label %8
8: ; preds = %8, %6
%9 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_filter.buf, i64 0, i64 0), %6 ], [ %12, %8 ]
%10 = load i8, i8* %9
%11 = tail call signext i8 @toupper(i8 signext %10)
store i8 %11, i8* %9
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = icmp eq i8 %11, 0
br i1 %13, label %14, label %8
14: ; preds = %8, %1, %3
%15 = phi i8* [ %0, %3 ], [ null, %1 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_filter.buf, i64 0, i64 0), %8 ]
ret i8* %15
}