#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 *strchr(char *, int);
char *strrchr(char *, int);
main(void) {
  int car = 'i';
  char cadena[] = "La biblioteca de C proporciona muchas funciones";
  char dec1[] = "          1         2         3         4         ";
  char uni2[] = "01234567890123456789012345678901234567890123456789";
  char *pdest;
  int resu;
  printf("Cadena en la que se busca: \n%s\n", cadena);
  printf("%s\n%s\n\n", dec1, uni2);
  printf("Buscar el carácter: %c\n\n", car);
  pdest = strchr(cadena, car);
  resu = pdest - cadena;
  if (pdest != NULL)
    printf("La %c primera está en la posición %d\n", car, resu);
  else
    printf("%c no se encuentra en la cadena\n");
  pdest = strrchr(cadena, car);
  resu = pdest - cadena;
  if (pdest != NULL)
    printf("La última %c está en la posición %d\n\n", car, resu);
  else
    printf("%c no se encuentra en la cadena\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x69,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x30,%edx
call   1060 <memcpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xeb7(%rip),%rsi
mov    $0x33,%edx
call   1060 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
lea    0xedf(%rip),%rsi
mov    $0x33,%edx
call   1060 <memcpy@plt>
lea    -0x40(%rbp),%rsi
lea    0xefd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0xc8(%rbp)
mov    -0xc8(%rbp),%rax
lea    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0xcc(%rbp)
cmpq   $0x0,-0xc8(%rbp)
je     1228 <main+0xe8>
mov    -0x8(%rbp),%esi
mov    -0xcc(%rbp),%edx
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1236 <main+0xf6>
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <strrchr@plt>
mov    %rax,-0xc8(%rbp)
mov    -0xc8(%rbp),%rax
lea    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0xcc(%rbp)
cmpq   $0x0,-0xc8(%rbp)
je     1287 <main+0x147>
mov    -0x8(%rbp),%esi
mov    -0xcc(%rbp),%edx
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1295 <main+0x155>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xb0,%rsp
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xeee(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xecf(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xeb0(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movl   $0x202020,0x9f(%rsp)
movaps 0xef9(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xedd(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec1(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0x393837,0x5f(%rsp)
lea    0xee0(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeec(%rip),%rdi
lea    0x70(%rsp),%rsi
lea    0x30(%rsp),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
mov    $0x69,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x69,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1229 <main+0xf9>
mov    %rsp,%rcx
sub    %ecx,%eax
lea    0xecc(%rip),%rdi
mov    $0x69,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1237 <main+0x107>
lea    0xedd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x69,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1265 <main+0x135>
mov    %rsp,%rcx
sub    %ecx,%eax
lea    0xed9(%rip),%rdi
mov    $0x69,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1273 <main+0x143>
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.cadena = [48 x i8] c"La biblioteca de C proporciona muchas funciones\00"
@__const.main.dec1 = [51 x i8] c" 1 2 3 4 \00"
@__const.main.uni2 = [51 x i8] c"01234567890123456789012345678901234567890123456789\00"
@.str = [32 x i8] c"Cadena en la que se busca: \0A%s\0A\00"
@.str.1 = [8 x i8] c"%s\0A%s\0A\0A\00"
@.str.2 = [26 x i8] c"Buscar el car\C3\A1cter: %c\0A\0A\00"
@.str.3 = [40 x i8] c"La %c primera est\C3\A1 en la posici\C3\B3n %d\0A\00"
@.str.4 = [33 x i8] c"%c no se encuentra en la cadena\0A\00"
@.str.5 = [41 x i8] c"La \C3\BAltima %c est\C3\A1 en la posici\C3\B3n %d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [48 x i8]
%4 = alloca [51 x i8]
%5 = alloca [51 x i8]
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %1
store i32 105, i32* %2
%8 = bitcast [48 x i8]* %3 to i8*
%9 = bitcast [51 x i8]* %4 to i8*
%10 = bitcast [51 x i8]* %5 to i8*
%11 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [51 x i8], [51 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %14)
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* %2
%20 = call i8* @strchr(i8* %18, i32 %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
store i32 %26, i32* %7
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %33
29: ; preds = %0
%30 = load i32, i32* %2
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %31)
br label %35
33: ; preds = %0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
%36 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%37 = load i32, i32* %2
%38 = call i8* @strrchr(i8* %36, i32 %37)
store i8* %38, i8** %6
%39 = load i8*, i8** %6
%40 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = trunc i64 %43 to i32
store i32 %44, i32* %7
%45 = load i8*, i8** %6
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %51
47: ; preds = %35
%48 = load i32, i32* %2
%49 = load i32, i32* %7
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %48, i32 %49)
br label %53
51: ; preds = %35
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %47
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@__const.main.cadena = [48 x i8] c"La biblioteca de C proporciona muchas funciones\00"
@__const.main.dec1 = [51 x i8] c" 1 2 3 4 \00"
@__const.main.uni2 = [51 x i8] c"01234567890123456789012345678901234567890123456789\00"
@.str = [32 x i8] c"Cadena en la que se busca: \0A%s\0A\00"
@.str.1 = [8 x i8] c"%s\0A%s\0A\0A\00"
@.str.2 = [26 x i8] c"Buscar el car\C3\A1cter: %c\0A\0A\00"
@.str.3 = [40 x i8] c"La %c primera est\C3\A1 en la posici\C3\B3n %d\0A\00"
@.str.4 = [33 x i8] c"%c no se encuentra en la cadena\0A\00"
@.str.5 = [41 x i8] c"La \C3\BAltima %c est\C3\A1 en la posici\C3\B3n %d\0A\0A\00"
define i32 @main() {
%1 = alloca [48 x i8]
%2 = alloca [51 x i8]
%3 = alloca [51 x i8]
%4 = getelementptr inbounds [48 x i8], [48 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [51 x i8], [51 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %4)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %6)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 105)
%10 = call i8* @strchr(i8* %4, i32 105)
%11 = ptrtoint [48 x i8]* %1 to i64
%12 = icmp eq i8* %10, null
br i1 %12, label %18, label %13
13: ; preds = %0
%14 = ptrtoint i8* %10 to i64
%15 = sub i64 %14, %11
%16 = trunc i64 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 105, i32 %16)
br label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = call i8* @strrchr(i8* %4, i32 105)
%22 = icmp eq i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = ptrtoint i8* %21 to i64
%25 = sub i64 %24, %11
%26 = trunc i64 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 105, i32 %26)
br label %30
28: ; preds = %20
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28, %23
ret i32 0
}