#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 *calloc(scalar_t__, int);
int error_code(int, char *, char *);
int /*<<< orphan*/ free(char *);
int mod_find_p(char *, char *, char *, char **);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strstr(char *, char *);
int mod_find_ps(char *mod_script, char *args, char **ret) {
  char *mod, *script;
  char *s, *str;
  int code;
  str = mod_script;
  if (!(s = strstr(str, ":")))
    return error_code(-1, "Bad request format for %s.", str);
  *s = 0;
  mod = calloc(1 + strlen(str), sizeof(char));
  strcpy(mod, str);
  script = calloc(1 + strlen(++s), sizeof(char));
  strcpy(script, s);
  *(s - 1) = ':';
  code = mod_find_p(mod, script, args, ret);
  (free(mod), (mod) = NULL);
  (free(script), (script) = NULL);
  return code;
}


x86 assembly (clang, -O0):
<mod_find_ps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11c7 <mod_find_ps+0x57>
mov    -0x40(%rbp),%rdx
mov    $0xffffffff,%edi
lea    0xe48(%rip),%rsi
call   1080 <error_code@plt>
mov    %eax,-0x4(%rbp)
jmp    1274 <mod_find_ps+0x104>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x38(%rbp)
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rax
movb   $0x3a,-0x1(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <mod_find_p@plt>
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_find_ps>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1225 <mod_find_ps+0xb5>
mov    %rax,%r13
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r13,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
movb   $0x3a,0x0(%r13)
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1070 <mod_find_p@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd4(%rip),%rsi
mov    $0xffffffff,%edi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <error_code@plt>

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@.str.1 = [27 x i8] c"Bad request format for %s.\00"
define i32 @mod_find_ps(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%13 = load i8*, i8** %5
store i8* %13, i8** %11
%14 = load i8*, i8** %11
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %10
%16 = icmp ne i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %3
%18 = load i8*, i8** %11
%19 = call i32 @error_code(i32 -1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i32 %19, i32* %4
br label %49
20: ; preds = %3
%21 = load i8*, i8** %10
store i8 0, i8* %21
%22 = load i8*, i8** %11
%23 = call i64 @strlen(i8* %22)
%24 = add nsw i64 1, %23
%25 = call i8* @calloc(i64 %24, i32 1)
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = load i8*, i8** %11
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = load i8*, i8** %10
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %10
%31 = call i64 @strlen(i8* %30)
%32 = add nsw i64 1, %31
%33 = call i8* @calloc(i64 %32, i32 1)
store i8* %33, i8** %9
%34 = load i8*, i8** %9
%35 = load i8*, i8** %10
%36 = call i32 @strcpy(i8* %34, i8* %35)
%37 = load i8*, i8** %10
%38 = getelementptr inbounds i8, i8* %37, i64 -1
store i8 58, i8* %38
%39 = load i8*, i8** %8
%40 = load i8*, i8** %9
%41 = load i8*, i8** %6
%42 = load i8**, i8*** %7
%43 = call i32 @mod_find_p(i8* %39, i8* %40, i8* %41, i8** %42)
store i32 %43, i32* %12
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
store i8* null, i8** %8
%46 = load i8*, i8** %9
%47 = call i32 @free(i8* %46)
store i8* null, i8** %9
%48 = load i32, i32* %12
store i32 %48, i32* %4
br label %49
49: ; preds = %20, %17
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c"Bad request format for %s.\00"
define i32 @mod_find_ps(i8* %0, i8* %1, i8** %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @error_code(i32 -1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %21
8: ; preds = %3
store i8 0, i8* %4
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = add nsw i64 %9, 1
%11 = tail call i8* @calloc(i64 %10, i32 1)
%12 = tail call i32 @strcpy(i8* %11, i8* %0)
%13 = getelementptr inbounds i8, i8* %4, i64 1
%14 = tail call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = tail call i8* @calloc(i64 %15, i32 1)
%17 = tail call i32 @strcpy(i8* %16, i8* %13)
store i8 58, i8* %4
%18 = tail call i32 @mod_find_p(i8* %11, i8* %16, i8* %1, i8** %2)
%19 = tail call i32 @free(i8* %11)
%20 = tail call i32 @free(i8* %16)
br label %21
21: ; preds = %8, %6
%22 = phi i32 [ %18, %8 ], [ %7, %6 ]
ret i32 %22
}