#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;
char *calloc(int, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int remove_new_line(char *);
char *replace_digit(char *, char *, int, char, int *);
int /*<<< orphan*/ stdin;
int main() {
  char line[100];
  fgets(line, 100, stdin);
  int lineLenght = remove_new_line(line);
  int changedDigit = 0;
  char *resultStr = calloc(lineLenght, sizeof(char));
  if (resultStr) {
    error("Can't allocate memory.");
  }
  resultStr = replace_digit(resultStr, line, lineLenght, '/', &changedDigit);
  printf("%s\n", resultStr);
  printf("%d has changed.", changedDigit);
  free(resultStr);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x70(%rbp),%rdi
call   1090 <remove_new_line@plt>
mov    %eax,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x74(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     11d4 <main+0x64>
lea    0xe31(%rip),%rdi
call   1080 <error@plt>
mov    -0x80(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
mov    $0x2f,%ecx
lea    -0x78(%rbp),%r8
call   1050 <replace_digit@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rdi
call   1030 <free@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   10a0 <remove_new_line@plt>
mov    %eax,%ebp
movl   $0x0,0xc(%rsp)
mov    %eax,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d3 <main+0x53>
lea    0xe32(%rip),%rdi
call   1090 <error@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
mov    %ebp,%edx
mov    $0x2f,%ecx
call   1060 <replace_digit@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [23 x i8] c"Can't allocate memory.\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [16 x i8] c"%d has changed.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 100, i32 %7)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = call i32 @remove_new_line(i8* %9)
store i32 %10, i32* %3
store i32 0, i32* %4
%11 = load i32, i32* %3
%12 = call i8* @calloc(i32 %11, i32 1)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
%18 = load i8*, i8** %5
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%20 = load i32, i32* %3
%21 = call i8* @replace_digit(i8* %18, i8* %19, i32 %20, i8 signext 47, i32* %4)
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
%28 = load i32, i32* @EXIT_SUCCESS
ret i32 %28
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [23 x i8] c"Can't allocate memory.\00"
@.str.2 = [16 x i8] c"%d has changed.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %3, i32 100, i32 %4)
%6 = call i32 @remove_new_line(i8* %3)
%7 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%8 = call i8* @calloc(i32 %6, i32 1)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i8* @replace_digit(i8* %8, i8* %3, i32 %6, i8 signext 47, i32* %2)
%14 = call i32 @puts(i8* dereferenceable(1) %13)
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 @free(i8* %13)
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}