#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
scalar_t__ strlen(char const *);
char *iupStrFileGetExt(const char *file_name) {
  if (!file_name)
    return NULL;
  else {
    int len = (int)strlen(file_name);
    int offset = len - 1;
    while (offset != 0) {
      if (file_name[offset] == '\\' || file_name[offset] == '/')
        return NULL;
      if (file_name[offset] == '.') {
        offset++;
        break;
      }
      offset--;
    }
    if (offset == 0)
      return NULL;
    {
      int ext_size = len - offset + 1;
      char *file_ext = (char *)malloc(ext_size);
      memcpy(file_ext, file_name + offset, ext_size);
      return file_ext;
    }
  }
}


x86 assembly (clang, -O0):
<iupStrFileGetExt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <iupStrFileGetExt+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1229 <iupStrFileGetExt+0xf9>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11db <iupStrFileGetExt+0xab>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     119d <iupStrFileGetExt+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11aa <iupStrFileGetExt+0x7a>
movq   $0x0,-0x8(%rbp)
jmp    1229 <iupStrFileGetExt+0xf9>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11cd <iupStrFileGetExt+0x9d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11db <iupStrFileGetExt+0xab>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1169 <iupStrFileGetExt+0x39>
cmpl   $0x0,-0x18(%rbp)
jne    11f2 <iupStrFileGetExt+0xc2>
movq   $0x0,-0x8(%rbp)
jmp    1229 <iupStrFileGetExt+0xf9>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iupStrFileGetExt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11cb <iupStrFileGetExt+0x9b>
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rcx
shl    $0x20,%rcx
movslq %eax,%rdx
movabs $0x100000000,%r12
add    %rcx,%r12
lea    (%rdx,%r15,1),%rcx
add    $0xffffffffffffffff,%rcx
xor    %r14d,%r14d
movabs $0xffffffff00000000,%rsi
ff ff ff
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    (%rax,%rbx,1),%edx
cmp    $0x1,%edx
je     11ce <iupStrFileGetExt+0x9e>
movzbl (%rcx,%rbx,1),%edx
cmp    $0x5c,%dl
je     11ce <iupStrFileGetExt+0x9e>
cmp    $0x2f,%dl
je     11ce <iupStrFileGetExt+0x9e>
add    %rsi,%r12
add    $0xffffffffffffffff,%rbx
cmp    $0x2e,%dl
jne    1180 <iupStrFileGetExt+0x50>
add    %ebx,%eax
cmp    $0xffffffff,%eax
je     11cb <iupStrFileGetExt+0x9b>
neg    %ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
sar    $0x20,%r12
add    %r12,%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
jmp    11ce <iupStrFileGetExt+0x9e>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @iupStrFileGetExt(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i8* null, i8** %2
br label %71
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %5
br label %17
17: ; preds = %48, %11
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %51
20: ; preds = %17
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 92
br i1 %27, label %36, label %28
28: ; preds = %20
%29 = load i8*, i8** %3
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 47
br i1 %35, label %36, label %37
36: ; preds = %28, %20
store i8* null, i8** %2
br label %71
37: ; preds = %28
%38 = load i8*, i8** %3
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 46
br i1 %44, label %45, label %48
45: ; preds = %37
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %51
48: ; preds = %37
%49 = load i32, i32* %5
%50 = add nsw i32 %49, -1
store i32 %50, i32* %5
br label %17
51: ; preds = %45, %17
%52 = load i32, i32* %5
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51
store i8* null, i8** %2
br label %71
55: ; preds = %51
%56 = load i32, i32* %4
%57 = load i32, i32* %5
%58 = sub nsw i32 %56, %57
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = call i64 @malloc(i32 %60)
%62 = inttoptr i64 %61 to i8*
store i8* %62, i8** %7
%63 = load i8*, i8** %7
%64 = load i8*, i8** %3
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i32, i32* %6
%69 = call i32 @memcpy(i8* %63, i8* %67, i32 %68)
%70 = load i8*, i8** %7
store i8* %70, i8** %2
br label %71
71: ; preds = %55, %54, %36, %10
%72 = load i8*, i8** %2
ret i8* %72
}

LLVM IR (-O2):
define i8* @iupStrFileGetExt(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %28, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = trunc i64 %4 to i32
%6 = shl i64 %4, 32
%7 = ashr exact i64 %6, 32
br label %8
8: ; preds = %13, %3
%9 = phi i64 [ %10, %13 ], [ %7, %3 ]
%10 = add nsw i64 %9, -1
%11 = trunc i64 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %28, label %13
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %0, i64 %10
%15 = load i8, i8* %14
switch i8 %15, label %8 [
i8 92, label %28
i8 47, label %28
i8 46, label %16
]
16: ; preds = %13
%17 = trunc i64 %9 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = sub nsw i32 %5, %17
%21 = add nsw i32 %20, 1
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = shl i64 %9, 32
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = tail call i32 @memcpy(i8* %23, i8* %26, i32 %21)
br label %28
28: ; preds = %8, %13, %13, %19, %16, %1
%29 = phi i8* [ null, %1 ], [ %23, %19 ], [ null, %16 ], [ null, %13 ], [ null, %13 ], [ null, %8 ]
ret i8* %29
}