#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(unsigned int);
unsigned int strlen(char *);
char *strrchr(char *, char);
char *getExtension(char *url) {
  char *tmp = strrchr(url, '.');
  char *res = malloc(strlen(tmp));
  unsigned int i = 0;
  while (i + 1 < strlen(tmp)) {
    res[i] = tmp[i + 1];
    i++;
  }
  return res;
}


x86 assembly (clang, -O0):
<getExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jae    11af <getExtension+0x7f>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <getExtension+0x39>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getExtension>:
push   %r15
push   %r14
push   %rbx
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jb     118d <getExtension+0x5d>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
mov    %al,-0x1(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1170 <getExtension+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @getExtension(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
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 i32 @strlen(i8* %8)
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
store i32 0, i32* %5
br label %11
11: ; preds = %17, %1
%12 = load i32, i32* %5
%13 = add i32 %12, 1
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = icmp ult i32 %13, %15
br i1 %16, label %17, label %30
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = add i32 %19, 1
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
%28 = load i32, i32* %5
%29 = add i32 %28, 1
store i32 %29, i32* %5
br label %11
30: ; preds = %11
%31 = load i8*, i8** %4
ret i8* %31
}

LLVM IR (-O2):
define noalias i8* @getExtension(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = tail call i32 @strlen(i8* %2)
%4 = tail call i8* @malloc(i32 %3)
%5 = tail call i32 @strlen(i8* %2)
%6 = icmp ugt i32 %5, 1
br i1 %6, label %7, label %18
7: ; preds = %1, %7
%8 = phi i64 [ %10, %7 ], [ 0, %1 ]
%9 = phi i64 [ %14, %7 ], [ 1, %1 ]
%10 = add nuw nsw i64 %8, 1
%11 = getelementptr inbounds i8, i8* %2, i64 %9
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %4, i64 %8
store i8 %12, i8* %13
%14 = add nuw nsw i64 %9, 1
%15 = tail call i32 @strlen(i8* %2)
%16 = zext i32 %15 to i64
%17 = icmp ult i64 %14, %16
br i1 %17, label %7, label %18
18: ; preds = %7, %1
ret i8* %4
}