#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 strlen(char *);
void get_file_extension(char *filename, char *extension) {
  int i, j, ctr = 0;
  extension[0] = 0;
  for (i = strlen(filename) - 1; i >= 0; i--) {
    if (filename[i] == '.')
      break;
  }
  if (i > 0) {
    for (j = i + 1; j < strlen(filename); j++) {
      extension[ctr++] = filename[j];
    }
    extension[ctr] = 0;
  }
}


x86 assembly (clang, -O0):
<get_file_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1174 <get_file_extension+0x64>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1161 <get_file_extension+0x51>
jmp    1174 <get_file_extension+0x64>
jmp    1166 <get_file_extension+0x56>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <get_file_extension+0x2d>
cmpl   $0x0,-0x14(%rbp)
jle    11dd <get_file_extension+0xcd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11d1 <get_file_extension+0xc1>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1187 <get_file_extension+0x77>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_extension>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
movb   $0x0,(%rsi)
call   1030 <strlen@plt>
mov    %eax,%ecx
movslq %eax,%rbx
add    $0x1,%rbx
nop
test   %ecx,%ecx
jle    119c <get_file_extension+0x8c>
add    $0xffffffffffffffff,%rbx
lea    -0x1(%rcx),%r12
cmpb   $0x2e,-0x1(%r15,%rcx,1)
mov    %r12,%rcx
jne    1130 <get_file_extension+0x20>
add    $0x1,%r12
cmp    $0x2,%r12d
jb     119c <get_file_extension+0x8c>
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    %r12d,%eax
jle    1195 <get_file_extension+0x85>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
mov    %al,(%r14,%r12,1)
add    $0x1,%r12
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1170 <get_file_extension+0x60>
mov    %r12d,%eax
jmp    1197 <get_file_extension+0x87>
xor    %eax,%eax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @get_file_extension(i8* %0, i8* nocapture writeonly %1) {
store i8 0, i8* %1
%3 = tail call i32 @strlen(i8* %0)
%4 = zext i32 %3 to i64
br label %5
5: ; preds = %10, %2
%6 = phi i64 [ %7, %10 ], [ %4, %2 ]
%7 = add nsw i64 %6, -1
%8 = trunc i64 %6 to i32
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %39
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %0, i64 %7
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 46
br i1 %13, label %14, label %5
14: ; preds = %10
%15 = trunc i64 %6 to i32
%16 = icmp ugt i32 %15, 1
br i1 %16, label %17, label %39
17: ; preds = %14
%18 = tail call i32 @strlen(i8* %0)
%19 = icmp sgt i32 %18, %15
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = shl i64 %6, 32
%22 = ashr exact i64 %21, 32
br label %23
23: ; preds = %20, %23
%24 = phi i64 [ %22, %20 ], [ %30, %23 ]
%25 = phi i64 [ 0, %20 ], [ %28, %23 ]
%26 = getelementptr inbounds i8, i8* %0, i64 %24
%27 = load i8, i8* %26
%28 = add nuw nsw i64 %25, 1
%29 = getelementptr inbounds i8, i8* %1, i64 %25
store i8 %27, i8* %29
%30 = add nsw i64 %24, 1
%31 = tail call i32 @strlen(i8* %0)
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %23, label %34
34: ; preds = %23
%35 = and i64 %28, 4294967295
br label %36
36: ; preds = %34, %17
%37 = phi i64 [ 0, %17 ], [ %35, %34 ]
%38 = getelementptr inbounds i8, i8* %1, i64 %37
store i8 0, i8* %38
br label %39
39: ; preds = %5, %36, %14
ret void
}