#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 /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void bad(char *str) {
  char buf[10], *p;
  strcpy(buf, str);
  for (p = buf; *p; p++) {
    if ((*p & 0xc0) == 0x40)
      *p ^= 0x20;
  }
  printf("%s\n", buf);
}


x86 assembly (clang, -O0):
<bad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x12(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x12(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1185 <bad+0x65>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
and    $0xc0,%eax
cmp    $0x40,%eax
jne    116f <bad+0x4f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    $0x20,%ecx
mov    %cl,(%rax)
jmp    1174 <bad+0x54>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1141 <bad+0x21>
lea    -0x12(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bad>:
sub    $0x18,%rsp
mov    %rdi,%rsi
lea    0xe(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0xe(%rsp),%al
test   %al,%al
je     115c <bad+0x3c>
lea    0xf(%rsp),%rcx
jmp    114b <bad+0x2b>
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
je     115c <bad+0x3c>
mov    %eax,%edx
and    $0xc0,%dl
cmp    $0x40,%dl
jne    1140 <bad+0x20>
xor    $0x20,%al
mov    %al,-0x1(%rcx)
jmp    1140 <bad+0x20>
lea    0xe9d(%rip),%rdi
lea    0xe(%rsp),%rsi
call   1040 <printf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define void @bad(i8* %0) {
%2 = alloca i8*
%3 = alloca [10 x i8]
%4 = alloca i8*
store i8* %0, i8** %2
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @strcpy(i8* %5, i8* %6)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8* %8, i8** %4
br label %9
9: ; preds = %26, %1
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = and i32 %16, 192
%18 = icmp eq i32 %17, 64
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = xor i32 %22, 32
%24 = trunc i32 %23 to i8
store i8 %24, i8* %20
br label %25
25: ; preds = %19, %13
br label %26
26: ; preds = %25
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
br label %9
29: ; preds = %9
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %30)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @bad(i8* %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
%5 = load i8, i8* %3
%6 = icmp eq i8 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %1, %14
%8 = phi i8 [ %16, %14 ], [ %5, %1 ]
%9 = phi i8* [ %15, %14 ], [ %3, %1 ]
%10 = and i8 %8, -64
%11 = icmp eq i8 %10, 64
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = xor i8 %8, 32
store i8 %13, i8* %9
br label %14
14: ; preds = %7, %12
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %7
18: ; preds = %14, %1
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
ret void
}