#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 EXIT_SUCCESS;
int comptaCaracter(char *, char);
int mygetchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char **argv) {
  char cadena[45], lletra;
  int i = 0, car;
  printf("Introdueix un text acabat en SALT DE LINIA: \n");
  while (i < 45 - 1 && (car = mygetchar()) != '\n') {
    cadena[i] = car;
    i++;
  }
  cadena[i] = 0;
  printf("\n¿Quina lletra vols comptar?: ");
  scanf("%c", &lletra);
  printf("\nLa lletra %c apareix %d vegades.\n\n", lletra,
         comptaCaracter(cadena, lletra));
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x48(%rbp)
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
cmpl   $0x2c,-0x48(%rbp)
mov    %al,-0x4d(%rbp)
jge    118d <main+0x4d>
mov    $0x0,%al
call   1030 <mygetchar@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0xa,%eax
setne  %al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    119d <main+0x5d>
jmp    11b8 <main+0x78>
mov    -0x4c(%rbp),%eax
mov    %al,%cl
movslq -0x48(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    116b <main+0x2b>
movslq -0x48(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
lea    -0x41(%rbp),%rsi
call   1060 <scanf@plt>
movsbl -0x41(%rbp),%eax
mov    %eax,-0x54(%rbp)
lea    -0x40(%rbp),%rdi
movsbl -0x41(%rbp),%esi
call   1050 <comptaCaracter@plt>
mov    -0x54(%rbp),%esi
mov    %eax,%edx
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <mygetchar@plt>
cmp    $0xa,%eax
je     118f <main+0x3f>
mov    %al,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x2c,%rbx
jne    1170 <main+0x20>
mov    $0x2c,%ebx
mov    %ebx,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe75(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1070 <scanf@plt>
movsbl 0xf(%rsp),%ebx
lea    0x10(%rsp),%rdi
mov    %ebx,%esi
call   1060 <comptaCaracter@plt>
lea    0xe56(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Introdueix un text acabat en SALT DE LINIA: \0A\00"
@.str.1 = [32 x i8] c"\0A\C2\BFQuina lletra vols comptar?: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [36 x i8] c"\0ALa lletra %c apareix %d vegades.\0A\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [45 x i8]
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %19, %2
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 44
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 (...) @mygetchar()
store i32 %15, i32* %9
%16 = icmp ne i32 %15, 10
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ false, %11 ], [ %16, %14 ]
br i1 %18, label %19, label %27
19: ; preds = %17
%20 = load i32, i32* %9
%21 = trunc i32 %20 to i8
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [45 x i8], [45 x i8]* %6, i64 0, i64 %23
store i8 %21, i8* %24
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %11
27: ; preds = %17
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [45 x i8], [45 x i8]* %6, i64 0, i64 %29
store i8 0, i8* %30
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%33 = load i8, i8* %7
%34 = sext i8 %33 to i32
%35 = getelementptr inbounds [45 x i8], [45 x i8]* %6, i64 0, i64 0
%36 = load i8, i8* %7
%37 = call i32 @comptaCaracter(i8* %35, i8 signext %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %37)
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}

LLVM IR (-O2):
@.str.1 = [32 x i8] c"\0A\C2\BFQuina lletra vols comptar?: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [36 x i8] c"\0ALa lletra %c apareix %d vegades.\0A\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [45 x i8] c"Introdueix un text acabat en SALT DE LINIA: \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [45 x i8]
%4 = alloca i8
%5 = getelementptr inbounds [45 x i8], [45 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %2, %11
%8 = phi i64 [ 0, %2 ], [ %14, %11 ]
%9 = tail call i32 (...) @mygetchar()
%10 = icmp eq i32 %9, 10
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = trunc i32 %9 to i8
%13 = getelementptr inbounds [45 x i8], [45 x i8]* %3, i64 0, i64 %8
store i8 %12, i8* %13
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, 44
br i1 %15, label %16, label %7
16: ; preds = %11, %7
%17 = phi i64 [ 44, %11 ], [ %8, %7 ]
%18 = and i64 %17, 4294967295
%19 = getelementptr inbounds [45 x i8], [45 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = call i32 @comptaCaracter(i8* %5, i8 signext %22)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}