#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(int);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
char *findextention(char *url) {
  int i, j;
  char *ext;
  for (i = strlen(url) - 1; url[i] != '.'; i--)
    ;
  ext = malloc(strlen(url) - i);
  i++;
  for (j = 0; url[i] != '\0'; i++, j++)
    ext[j] = url[i];
  ext[j] = '\0';
  printf("%s\n", ext);
  return ext;
}


x86 assembly (clang, -O0):
<findextention>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1173 <findextention+0x43>
jmp    1165 <findextention+0x35>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <findextention+0x1b>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
sub    -0xc(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11dc <findextention+0xac>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119a <findextention+0x6a>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findextention>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ebp
movslq %eax,%rcx
lea    (%rcx,%r14,1),%rax
add    $0xffffffffffffffff,%rax
shl    $0x20,%rcx
movabs $0x100000000,%rbx
add    %rcx,%rbx
movabs $0xffffffff00000000,%rcx
ff ff ff
nopw   0x0(%rax,%rax,1)
add    %rcx,%rbx
add    $0xffffffff,%ebp
cmpb   $0x2e,(%rax)
lea    -0x1(%rax),%rax
jne    1170 <findextention+0x40>
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %ebp,%eax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
sar    $0x20,%rbx
mov    (%r14,%rbx,1),%al
test   %al,%al
je     11c4 <findextention+0x94>
add    $0x1,%ebp
movslq %ebp,%rcx
lea    (%r14,%rcx,1),%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
nop
mov    %al,(%r15,%rcx,1)
movzbl (%rdx,%rcx,1),%eax
add    $0x1,%rcx
test   %al,%al
jne    11b0 <findextention+0x80>
mov    %ecx,%eax
jmp    11c6 <findextention+0x96>
xor    %eax,%eax
movb   $0x0,(%r15,%rax,1)
lea    0xe2e(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i8* @findextention(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %3
br label %9
9: ; preds = %18, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 46
br i1 %16, label %17, label %21
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %3
%20 = add nsw i32 %19, -1
store i32 %20, i32* %3
br label %9
21: ; preds = %9
%22 = load i8*, i8** %2
%23 = call i32 @strlen(i8* %22)
%24 = load i32, i32* %3
%25 = sub nsw i32 %23, %24
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %5
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
store i32 0, i32* %4
br label %29
29: ; preds = %47, %21
%30 = load i8*, i8** %2
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %52
37: ; preds = %29
%38 = load i8*, i8** %2
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = load i8*, i8** %5
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
br label %47
47: ; preds = %37
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %29
52: ; preds = %29
%53 = load i8*, i8** %5
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 0, i8* %56
%57 = load i8*, i8** %5
%58 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %57)
%59 = load i8*, i8** %5
ret i8* %59
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i8* @findextention(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ %6, %4 ], [ %3, %1 ]
%6 = add i64 %5, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 46
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = trunc i64 %6 to i32
%12 = tail call i32 @strlen(i8* %0)
%13 = sub nsw i32 %12, %11
%14 = tail call i8* @malloc(i32 %13)
%15 = shl i64 %5, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %32, label %20
20: ; preds = %10, %20
%21 = phi i64 [ %26, %20 ], [ 0, %10 ]
%22 = phi i64 [ %25, %20 ], [ %16, %10 ]
%23 = phi i8 [ %28, %20 ], [ %18, %10 ]
%24 = getelementptr inbounds i8, i8* %14, i64 %21
store i8 %23, i8* %24
%25 = add i64 %22, 1
%26 = add nuw i64 %21, 1
%27 = getelementptr inbounds i8, i8* %0, i64 %25
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %20
30: ; preds = %20
%31 = and i64 %26, 4294967295
br label %32
32: ; preds = %30, %10
%33 = phi i64 [ 0, %10 ], [ %31, %30 ]
%34 = getelementptr inbounds i8, i8* %14, i64 %33
store i8 0, i8* %34
%35 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
ret i8* %14
}