#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 */
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
size_t strlen(char *);
char *strrchr(char *, char);
char *gen_path(char *in, int mode) {
  static char extention[] = ".ftf";
  size_t size2 = strlen(extention);
  size_t size1 = strlen(in);
  char *out;
  if ((in == NULL) || ((out = malloc(size1 + size2))) == NULL)
    return NULL;
  memcpy(out, in, size1);
  switch (mode) {
  case 1: {
    memcpy(out + size1, extention, size2);
    break;
  }
  case 0: {
    puts("decryption gen_path");
    char *last_dot = strrchr(out, '.');
    *last_dot = '\0';
    printf("last_dot= %s\n", out);
    break;
  }
  default: {
    return NULL;
    break;
  }
  }
  return out;
}


x86 assembly (clang, -O0):
<gen_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0x2eda(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b2 <gen_path+0x52>
mov    -0x28(%rbp),%rdi
add    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11bf <gen_path+0x5f>
movq   $0x0,-0x8(%rbp)
jmp    1260 <gen_path+0x100>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
test   %eax,%eax
je     1211 <gen_path+0xb1>
jmp    11e3 <gen_path+0x83>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
jne    124b <gen_path+0xeb>
jmp    11f4 <gen_path+0x94>
mov    -0x30(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0x2e49(%rip),%rsi
call   1070 <memcpy@plt>
jmp    1258 <gen_path+0xf8>
lea    0xde8(%rip),%rdi
call   1030 <puts@plt>
mov    -0x30(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rsi
lea    0xdd3(%rip),%rdi
call   1050 <printf@plt>
jmp    1258 <gen_path+0xf8>
movq   $0x0,-0x8(%rbp)
jmp    1260 <gen_path+0x100>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%rbp
lea    0x2edb(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1040 <strlen@plt>
test   %rbp,%rbp
je     11ce <gen_path+0x6e>
mov    %rax,%r12
lea    (%rax,%r14,1),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     11ce <gen_path+0x6e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1070 <memcpy@plt>
test   %r15d,%r15d
je     11dc <gen_path+0x7c>
cmp    $0x1,%r15d
jne    11ce <gen_path+0x6e>
mov    %rbx,%rdi
add    %r12,%rdi
lea    0x2e8c(%rip),%rsi
mov    %r14,%rdx
call   1070 <memcpy@plt>
jmp    11d0 <gen_path+0x70>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
movb   $0x0,(%rax)
lea    0xe15(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    11d0 <gen_path+0x70>

LLVM IR (-O0):
@gen_path.extention = internal global [5 x i8] c".ftf\00"
@.str = [20 x i8] c"decryption gen_path\00"
@.str.1 = [14 x i8] c"last_dot= %s\0A\00"
define i8* @gen_path(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @gen_path.extention, i64 0, i64 0))
store i64 %10, i64* %6
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %7
%13 = load i8*, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %21, label %15
15: ; preds = %2
%16 = load i64, i64* %7
%17 = load i64, i64* %6
%18 = add i64 %16, %17
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %8
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %15, %2
store i8* null, i8** %3
br label %44
22: ; preds = %15
%23 = load i8*, i8** %8
%24 = load i8*, i8** %4
%25 = load i64, i64* %7
%26 = call i32 @memcpy(i8* %23, i8* %24, i64 %25)
%27 = load i32, i32* %5
switch i32 %27, label %41 [
i32 1, label %28
i32 0, label %34
]
28: ; preds = %22
%29 = load i8*, i8** %8
%30 = load i64, i64* %7
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i64, i64* %6
%33 = call i32 @memcpy(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @gen_path.extention, i64 0, i64 0), i64 %32)
br label %42
34: ; preds = %22
%35 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%36 = load i8*, i8** %8
%37 = call i8* @strrchr(i8* %36, i8 signext 46)
store i8* %37, i8** %9
%38 = load i8*, i8** %9
store i8 0, i8* %38
%39 = load i8*, i8** %8
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %42
41: ; preds = %22
store i8* null, i8** %3
br label %44
42: ; preds = %34, %28
%43 = load i8*, i8** %8
store i8* %43, i8** %3
br label %44
44: ; preds = %42, %41, %21
%45 = load i8*, i8** %3
ret i8* %45
}

LLVM IR (-O2):
@gen_path.extention = internal global [5 x i8] c".ftf\00"
@.str = [20 x i8] c"decryption gen_path\00"
@.str.1 = [14 x i8] c"last_dot= %s\0A\00"
define i8* @gen_path(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @gen_path.extention, i64 0, i64 0))
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp eq i8* %0, null
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = add i64 %4, %3
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = tail call i32 @memcpy(i8* %8, i8* %0, i64 %4)
switch i32 %1, label %19 [
i32 1, label %12
i32 0, label %15
]
12: ; preds = %10
%13 = getelementptr inbounds i8, i8* %8, i64 %4
%14 = tail call i32 @memcpy(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @gen_path.extention, i64 0, i64 0), i64 %3)
br label %19
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = tail call i8* @strrchr(i8* %8, i8 signext 46)
store i8 0, i8* %17
%18 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %19
19: ; preds = %12, %15, %10, %2, %6
%20 = phi i8* [ null, %6 ], [ null, %2 ], [ null, %10 ], [ %8, %15 ], [ %8, %12 ]
ret i8* %20
}