#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 *alloca(int);
int /*<<< orphan*/ free(char *);
scalar_t__ is_md5(char const *);
char *md5(char const *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ rename(char const *, char *);
int strlen(char *);
void *strrchr(char const *, char);
void process_file(const char *filepath, int s) {
  const char *filename = strrchr(filepath, '/');
  int path_len;
  if (!filename) {
    filename = filepath;
    path_len = 0;
  } else {
    filename++;
    path_len = filename - filepath;
  }
  if (!s && is_md5(filename)) {
    printf("Skipping %s (Use -s)\n", filename);
    return;
  }
  char *hash = md5(filepath);
  if (!hash)
    return;
  char *ext = strrchr(filename, '.');
  int ext_len = ext ? strlen(ext) : 0;
  int size = (path_len + 32 + ext_len + 1);
  char *new_filepath = alloca(size);
  if (path_len)
    memcpy(new_filepath, filepath, path_len);
  memcpy(new_filepath + path_len, hash, 32);
  if (ext)
    memcpy(new_filepath + path_len + 32, ext, ext_len);
  new_filepath[size - 1] = '\0';
  rename(filepath, new_filepath);
  printf("Renaming %s to %s\n", filepath, new_filepath);
  free(hash);
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <process_file+0x40>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    11ea <process_file+0x5a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    121e <process_file+0x8e>
mov    -0x18(%rbp),%rdi
call   10b0 <is_md5@plt>
cmp    $0x0,%rax
je     121e <process_file+0x8e>
mov    -0x18(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    132a <process_file+0x19a>
mov    -0x8(%rbp),%rdi
call   10a0 <md5@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    123b <process_file+0xab>
jmp    132a <process_file+0x19a>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1269 <process_file+0xd9>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
jmp    1273 <process_file+0xe3>
xor    %eax,%eax
mov    %eax,-0x44(%rbp)
jmp    1273 <process_file+0xe3>
mov    -0x44(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%eax
add    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
call   1070 <alloca@plt>
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12ae <process_file+0x11e>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x40(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    $0x20,%edx
call   1080 <memcpy@plt>
cmpq   $0x0,-0x30(%rbp)
je     12ed <process_file+0x15d>
mov    -0x40(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x20,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1090 <rename@plt>
mov    -0x8(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    $0x2f,%esi
call   1060 <strrchr@plt>
lea    0x1(%rax),%rbp
mov    %ebp,%ecx
sub    %r15d,%ecx
xor    %ebx,%ebx
test   %rax,%rax
cmovne %ecx,%ebx
cmove  %r15,%rbp
test   %r14d,%r14d
je     11f6 <process_file+0x66>
mov    %r15,%rdi
call   10a0 <md5@plt>
test   %rax,%rax
je     1222 <process_file+0x92>
mov    %rax,%r14
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,%r12
test   %rax,%rax
je     1231 <process_file+0xa1>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
jmp    1233 <process_file+0xa3>
mov    %rbp,%rdi
call   10b0 <is_md5@plt>
test   %rax,%rax
je     11c5 <process_file+0x35>
lea    0xdf6(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
lea    (%rbx,%rbp,1),%edi
add    $0x21,%edi
call   1070 <alloca@plt>
mov    %rax,%r13
test   %ebx,%ebx
je     1252 <process_file+0xc2>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1080 <memcpy@plt>
lea    (%rbx,%rbp,1),%eax
add    $0x20,%eax
mov    %eax,0x4(%rsp)
movslq %ebx,%rax
mov    %r13,%rbx
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x20,%edx
call   1080 <memcpy@plt>
test   %r12,%r12
je     128b <process_file+0xfb>
add    $0x20,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1080 <memcpy@plt>
movslq 0x4(%rsp),%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <rename@plt>
lea    0xd6e(%rip),%rdi
mov    %r15,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Skipping %s (Use -s)\0A\00"
@.str.1 = [19 x i8] c"Renaming %s to %s\0A\00"
define void @process_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%12 = load i8*, i8** %3
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = load i8*, i8** %3
store i8* %17, i8** %5
store i32 0, i32* %6
br label %27
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
store i32 %26, i32* %6
br label %27
27: ; preds = %18, %16
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %27
%31 = load i8*, i8** %5
%32 = call i64 @is_md5(i8* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i8*, i8** %5
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %35)
br label %100
37: ; preds = %30, %27
%38 = load i8*, i8** %3
%39 = call i8* @md5(i8* %38)
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = icmp ne i8* %40, null
br i1 %41, label %43, label %42
42: ; preds = %37
br label %100
43: ; preds = %37
%44 = load i8*, i8** %5
%45 = call i8* @strrchr(i8* %44, i8 signext 46)
store i8* %45, i8** %8
%46 = load i8*, i8** %8
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i8*, i8** %8
%50 = call i32 @strlen(i8* %49)
br label %52
51: ; preds = %43
br label %52
52: ; preds = %51, %48
%53 = phi i32 [ %50, %48 ], [ 0, %51 ]
store i32 %53, i32* %9
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 32
%56 = load i32, i32* %9
%57 = add nsw i32 %55, %56
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = call i8* @alloca(i32 %59)
store i8* %60, i8** %11
%61 = load i32, i32* %6
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %52
%64 = load i8*, i8** %11
%65 = load i8*, i8** %3
%66 = load i32, i32* %6
%67 = call i32 @memcpy(i8* %64, i8* %65, i32 %66)
br label %68
68: ; preds = %63, %52
%69 = load i8*, i8** %11
%70 = load i32, i32* %6
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i8*, i8** %7
%74 = call i32 @memcpy(i8* %72, i8* %73, i32 32)
%75 = load i8*, i8** %8
%76 = icmp ne i8* %75, null
br i1 %76, label %77, label %86
77: ; preds = %68
%78 = load i8*, i8** %11
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = getelementptr inbounds i8, i8* %81, i64 32
%83 = load i8*, i8** %8
%84 = load i32, i32* %9
%85 = call i32 @memcpy(i8* %82, i8* %83, i32 %84)
br label %86
86: ; preds = %77, %68
%87 = load i8*, i8** %11
%88 = load i32, i32* %10
%89 = sub nsw i32 %88, 1
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %87, i64 %90
store i8 0, i8* %91
%92 = load i8*, i8** %3
%93 = load i8*, i8** %11
%94 = call i32 @rename(i8* %92, i8* %93)
%95 = load i8*, i8** %3
%96 = load i8*, i8** %11
%97 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %95, i8* %96)
%98 = load i8*, i8** %7
%99 = call i32 @free(i8* %98)
br label %100
100: ; preds = %86, %42, %34
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Skipping %s (Use -s)\0A\00"
@.str.1 = [19 x i8] c"Renaming %s to %s\0A\00"
define void @process_file(i8* %0, i32 %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
%5 = getelementptr inbounds i8, i8* %3, i64 1
%6 = ptrtoint i8* %5 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = trunc i64 %8 to i32
%10 = select i1 %4, i32 0, i32 %9
%11 = select i1 %4, i8* %0, i8* %5
%12 = icmp eq i32 %1, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = tail call i64 @is_md5(i8* %11)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %48
18: ; preds = %13, %2
%19 = tail call i8* @md5(i8* %0)
%20 = icmp eq i8* %19, null
br i1 %20, label %48, label %21
21: ; preds = %18
%22 = tail call i8* @strrchr(i8* dereferenceable(1) %11, i8 signext 46)
%23 = icmp eq i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @strlen(i8* %22)
br label %26
26: ; preds = %21, %24
%27 = phi i32 [ %25, %24 ], [ 0, %21 ]
%28 = add nsw i32 %10, 32
%29 = add nsw i32 %28, %27
%30 = add nsw i32 %29, 1
%31 = tail call i8* @alloca(i32 %30)
%32 = icmp eq i32 %10, 0
br i1 %32, label %35, label %33
33: ; preds = %26
%34 = tail call i32 @memcpy(i8* %31, i8* %0, i32 %10)
br label %35
35: ; preds = %33, %26
%36 = sext i32 %10 to i64
%37 = getelementptr inbounds i8, i8* %31, i64 %36
%38 = tail call i32 @memcpy(i8* %37, i8* %19, i32 32)
br i1 %23, label %42, label %39
39: ; preds = %35
%40 = getelementptr inbounds i8, i8* %37, i64 32
%41 = tail call i32 @memcpy(i8* %40, i8* %22, i32 %27)
br label %42
42: ; preds = %39, %35
%43 = sext i32 %29 to i64
%44 = getelementptr inbounds i8, i8* %31, i64 %43
store i8 0, i8* %44
%45 = tail call i32 @rename(i8* %0, i8* %31)
%46 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %31)
%47 = tail call i32 @free(i8* %19)
br label %48
48: ; preds = %42, %18, %16
ret void
}