#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
char *scalloc(scalar_t__, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, scalar_t__);
char *strrchr(char const *, char);
*check_and_gen_name(const char *input_name) {
  char *ext = strrchr(input_name, '.');
  if (strcmp(ext, ".tiff")) {
    fprintf(stderr, "erreur: L'extension de fichier n'est pas .tiff !\n");
    exit(EXIT_FAILURE);
  }
  char *jpeg_ext = ".jpeg";
  char *output_name = scalloc((strlen(input_name) + 1), sizeof(char));
  strncpy(output_name, input_name, strlen(input_name) - strlen(ext));
  strcat(output_name, jpeg_ext);
  printf("output_name: %s\n", output_name);
  return output_name;
}


x86 assembly (clang, -O0):
<check_and_gen_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11eb <check_and_gen_name+0x5b>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xe46(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1090 <scalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
sub    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rsi
lea    0xdd8(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_and_gen_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,%r14
lea    0xe51(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1226 <check_and_gen_name+0x96>
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1090 <scalloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
lea    0xe38(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strcat@plt>
lea    0xe2f(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c".tiff\00"
@stderr = global i32 0
@.str.1 = [50 x i8] c"erreur: L'extension de fichier n'est pas .tiff !\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c".jpeg\00"
@.str.3 = [17 x i8] c"output_name: %s\0A\00"
define i32* @check_and_gen_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strrchr(i8* %6, i8 signext 46)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %4
%17 = load i8*, i8** %2
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = call i8* @scalloc(i64 %19, i32 1)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = load i8*, i8** %2
%23 = load i8*, i8** %2
%24 = call i64 @strlen(i8* %23)
%25 = load i8*, i8** %3
%26 = call i64 @strlen(i8* %25)
%27 = sub nsw i64 %24, %26
%28 = call i32 @strncpy(i8* %21, i8* %22, i64 %27)
%29 = load i8*, i8** %5
%30 = load i8*, i8** %4
%31 = call i32 @strcat(i8* %29, i8* %30)
%32 = load i8*, i8** %5
%33 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %5
%35 = bitcast i8* %34 to i32*
ret i32* %35
}

LLVM IR (-O2):
@.str = [6 x i8] c".tiff\00"
@stderr = global i32 0
@.str.1 = [50 x i8] c"erreur: L'extension de fichier n'est pas .tiff !\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c".jpeg\00"
@.str.3 = [17 x i8] c"output_name: %s\0A\00"
define i32* @check_and_gen_name(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = add nsw i64 %11, 1
%13 = tail call i8* @scalloc(i64 %12, i32 1)
%14 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%15 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%16 = sub nsw i64 %14, %15
%17 = tail call i32 @strncpy(i8* %13, i8* %0, i64 %16)
%18 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%20 = bitcast i8* %13 to i32*
ret i32* %20
}