#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 count_char_in_str(char *, char);
char *delete_a_char_in_str(char *, int, char);
int my_str_length(char *);
char find_the_first_only_one_char(const char *p) {
  char *q = (char *)p;
  int length;
  while (1) {
    length = my_str_length(q);
    if (count_char_in_str(q, q[0]) > 1) {
      q = delete_a_char_in_str(q, length, q[0]);
    } else {
      return q[0];
    }
  }
  return q[0];
}


x86 assembly (clang, -O0):
<find_the_first_only_one_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <my_str_length@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
call   1030 <count_char_in_str@plt>
cmp    $0x1,%eax
jle    1185 <find_the_first_only_one_char+0x55>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
call   1050 <delete_a_char_in_str@plt>
mov    %rax,-0x10(%rbp)
jmp    1192 <find_the_first_only_one_char+0x62>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    1144 <find_the_first_only_one_char+0x14>

x86 assembly (clang, -O2):
<find_the_first_only_one_char>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <my_str_length@plt>
mov    %eax,%ebp
movsbl (%rbx),%esi
mov    %rbx,%rdi
call   1030 <count_char_in_str@plt>
cmp    $0x2,%eax
jl     117a <find_the_first_only_one_char+0x4a>
nopl   (%rax)
movsbl (%rbx),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <delete_a_char_in_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <my_str_length@plt>
mov    %eax,%ebp
movsbl (%rbx),%esi
mov    %rbx,%rdi
call   1030 <count_char_in_str@plt>
cmp    $0x1,%eax
jg     1150 <find_the_first_only_one_char+0x20>
mov    (%rbx),%al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @find_the_first_only_one_char(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %1, %26
%7 = load i8*, i8** %3
%8 = call i32 @my_str_length(i8* %7)
store i32 %8, i32* %4
%9 = load i8*, i8** %3
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = call i32 @count_char_in_str(i8* %9, i8 signext %12)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %22
15: ; preds = %6
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = call i8* @delete_a_char_in_str(i8* %16, i32 %17, i8 signext %20)
store i8* %21, i8** %3
br label %26
22: ; preds = %6
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
ret i8 %25
26: ; preds = %15
br label %6
}

LLVM IR (-O2):
define signext i8 @find_the_first_only_one_char(i8* %0) {
%2 = tail call i32 @my_str_length(i8* %0)
%3 = load i8, i8* %0
%4 = tail call i32 @count_char_in_str(i8* %0, i8 signext %3)
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %15
6: ; preds = %1, %6
%7 = phi i32 [ %11, %6 ], [ %2, %1 ]
%8 = phi i8* [ %10, %6 ], [ %0, %1 ]
%9 = load i8, i8* %8
%10 = tail call i8* @delete_a_char_in_str(i8* %8, i32 %7, i8 signext %9)
%11 = tail call i32 @my_str_length(i8* %10)
%12 = load i8, i8* %10
%13 = tail call i32 @count_char_in_str(i8* %10, i8 signext %12)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %6, label %15
15: ; preds = %6, %1
%16 = phi i8* [ %0, %1 ], [ %10, %6 ]
%17 = load i8, i8* %16
ret i8 %17
}