#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*/ memset(char *, int /*<<< orphan*/, int);
char *strdup(char *);
int strlen(char *);
char *setstr(char *str) {
  char buf[10];
  int i;
  int flag;
  char *p = NULL;
  p = buf;
  memset(buf, 0, 10);
  flag = 0;
  for (i = 0; i < strlen(str); i++) {
    int j;
    for (j = 0; j < strlen(buf); j++) {
      if (buf[j] == str[i]) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      flag = 0;
      continue;
    }
    *p++ = str[i];
  }
  return strdup(buf);
}


x86 assembly (clang, -O0):
<setstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x12(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jge    1225 <setstr+0xf5>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x12(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    11e5 <setstr+0xb5>
movslq -0x2c(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11d2 <setstr+0xa2>
movl   $0x1,-0x1c(%rbp)
jmp    11e5 <setstr+0xb5>
jmp    11d7 <setstr+0xa7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118d <setstr+0x5d>
cmpl   $0x1,-0x1c(%rbp)
jne    11fb <setstr+0xcb>
movl   $0x0,-0x1c(%rbp)
jmp    1217 <setstr+0xe7>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116a <setstr+0x3a>
lea    -0x12(%rbp),%rdi
call   1050 <strdup@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setstr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
lea    0x6(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11c0 <setstr+0x90>
xor    %r13d,%r13d
mov    %r14,%r12
jmp    118f <setstr+0x5f>
nopl   0x0(%rax,%rax,1)
mov    (%r15,%r13,1),%al
mov    %al,(%r12)
add    $0x1,%r12
add    $0x1,%r13
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%r13
jge    11c0 <setstr+0x90>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1170 <setstr+0x40>
xor    %ebx,%ebx
nopl   (%rax)
movzbl 0x6(%rsp,%rbx,1),%eax
cmp    (%r15,%r13,1),%al
je     117c <setstr+0x4c>
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11a0 <setstr+0x70>
jmp    1170 <setstr+0x40>
lea    0x6(%rsp),%rdi
call   1050 <strdup@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @setstr(i8* %0) {
%2 = alloca i8*
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %6
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8* %8, i8** %6
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 10)
store i32 0, i32* %5
store i32 0, i32* %4
br label %11
11: ; preds = %52, %1
%12 = load i32, i32* %4
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %55
16: ; preds = %11
store i32 0, i32* %7
br label %17
17: ; preds = %37, %16
%18 = load i32, i32* %7
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %40
22: ; preds = %17
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i8*, i8** %2
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %27, %33
br i1 %34, label %35, label %36
35: ; preds = %22
store i32 1, i32* %5
br label %40
36: ; preds = %22
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %17
40: ; preds = %35, %17
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 0, i32* %5
br label %52
44: ; preds = %40
%45 = load i8*, i8** %2
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %6
store i8 %49, i8* %50
br label %52
52: ; preds = %44, %43
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %11
55: ; preds = %11
%56 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%57 = call i8* @strdup(i8* %56)
ret i8* %57
}

LLVM IR (-O2):
define noalias i8* @setstr(i8* %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 10)
%5 = call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %35
7: ; preds = %1, %29
%8 = phi i64 [ %31, %29 ], [ 0, %1 ]
%9 = phi i8* [ %30, %29 ], [ %3, %1 ]
%10 = call i32 @strlen(i8* %3)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %0, i64 %8
br label %18
14: ; preds = %18
%15 = call i32 @strlen(i8* %3)
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %24, %16
br i1 %17, label %18, label %25
18: ; preds = %12, %14
%19 = phi i64 [ 0, %12 ], [ %24, %14 ]
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = load i8, i8* %13
%23 = icmp eq i8 %21, %22
%24 = add nuw nsw i64 %19, 1
br i1 %23, label %29, label %14
25: ; preds = %14, %7
%26 = getelementptr inbounds i8, i8* %0, i64 %8
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %27, i8* %9
br label %29
29: ; preds = %18, %25
%30 = phi i8* [ %28, %25 ], [ %9, %18 ]
%31 = add nuw nsw i64 %8, 1
%32 = call i32 @strlen(i8* %0)
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %7, label %35
35: ; preds = %29, %1
%36 = call i8* @strdup(i8* %3)
ret i8* %36
}