#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 error_code(int, char *, char *);
int mod_find_ps(char *, char *, int /*<<< orphan*/ *);
char *realloc(char *, size_t);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
int main(int argc, char **argv) {
  char *args = NULL;
  char *s, *str, **p;
  size_t n = 0;
  if (argc < 2)
    return error_code(-1, "Too few paremeters for %s.", *argv);
  if (!(s = strstr(str = argv[1], ":")))
    return error_code(-1, "Bad request format for %s.", *argv);
  if (argc > 2) {
    p = argv + 2;
    do {
      n += 256;
      args = realloc(args, n * sizeof(char));
      if (n == 256)
        strcpy(args, *p);
      else {
        strcat(args, " ");
        strcat(args, *p);
      }
    } while (*(++p));
  }
  return mod_find_ps(str, args, NULL);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b0 <main+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0xffffffff,%edi
lea    0xe5d(%rip),%rsi
call   1050 <error_code@plt>
mov    %eax,-0x4(%rbp)
jmp    12aa <main+0x14a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    %rdi,-0x28(%rbp)
lea    0xe58(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f6 <main+0x96>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0xffffffff,%edi
lea    0xe34(%rip),%rsi
call   1050 <error_code@plt>
mov    %eax,-0x4(%rbp)
jmp    12aa <main+0x14a>
cmpl   $0x2,-0x8(%rbp)
jle    1296 <main+0x136>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x100,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
shl    $0x0,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x100,-0x38(%rbp)
jne    1252 <main+0xf2>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
jmp    1272 <main+0x112>
mov    -0x18(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   1070 <strcat@plt>
jmp    1277 <main+0x117>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x30(%rbp)
cmpq   $0x0,0x8(%rax)
jne    120c <main+0xac>
jmp    1296 <main+0x136>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <mod_find_ps@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
cmp    $0x1,%edi
jg     1181 <main+0x21>
mov    (%r12),%rdx
lea    0xe84(%rip),%rsi
jmp    121b <main+0xbb>
mov    %edi,%ebx
mov    0x8(%r12),%r14
mov    %r14,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1210 <main+0xb0>
cmp    $0x3,%ebx
jb     122e <main+0xce>
add    $0x10,%r12
mov    $0x100,%ebx
xor    %r15d,%r15d
lea    0xe80(%rip),%r13
jmp    11eb <main+0x8b>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
mov    (%r12),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
add    $0x100,%rbx
cmpq   $0x0,0x8(%r12)
lea    0x8(%r12),%r12
je     1231 <main+0xd1>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <realloc@plt>
mov    %rax,%r15
cmp    $0x100,%rbx
jne    11c0 <main+0x60>
mov    (%r12),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
jmp    11d7 <main+0x77>
mov    (%r12),%rdx
lea    0xe00(%rip),%rsi
mov    $0xffffffff,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <error_code@plt>
xor    %r15d,%r15d
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <mod_find_ps@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Too few paremeters for %s.\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [27 x i8] c"Bad request format for %s.\00"
@.str.3 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i64 0, i64* %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = load i8*, i8** %14
%16 = call i32 @error_code(i32 -1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 %16, i32* %3
br label %65
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %8
%21 = call i8* @strstr(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %21, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = call i32 @error_code(i32 -1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %25)
store i32 %26, i32* %3
br label %65
27: ; preds = %17
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 2
br i1 %29, label %30, label %61
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
store i8** %32, i8*** %9
br label %33
33: ; preds = %55, %30
%34 = load i64, i64* %10
%35 = add i64 %34, 256
store i64 %35, i64* %10
%36 = load i8*, i8** %6
%37 = load i64, i64* %10
%38 = mul i64 %37, 1
%39 = call i8* @realloc(i8* %36, i64 %38)
store i8* %39, i8** %6
%40 = load i64, i64* %10
%41 = icmp eq i64 %40, 256
br i1 %41, label %42, label %47
42: ; preds = %33
%43 = load i8*, i8** %6
%44 = load i8**, i8*** %9
%45 = load i8*, i8** %44
%46 = call i32 @strcpy(i8* %43, i8* %45)
br label %54
47: ; preds = %33
%48 = load i8*, i8** %6
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%50 = load i8*, i8** %6
%51 = load i8**, i8*** %9
%52 = load i8*, i8** %51
%53 = call i32 @strcat(i8* %50, i8* %52)
br label %54
54: ; preds = %47, %42
br label %55
55: ; preds = %54
%56 = load i8**, i8*** %9
%57 = getelementptr inbounds i8*, i8** %56, i32 1
store i8** %57, i8*** %9
%58 = load i8*, i8** %57
%59 = icmp ne i8* %58, null
br i1 %59, label %33, label %60
60: ; preds = %55
br label %61
61: ; preds = %60, %27
%62 = load i8*, i8** %8
%63 = load i8*, i8** %6
%64 = call i32 @mod_find_ps(i8* %62, i8* %63, i32* null)
store i32 %64, i32* %3
br label %65
65: ; preds = %61, %23, %13
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [27 x i8] c"Too few paremeters for %s.\00"
@.str.2 = [27 x i8] c"Bad request format for %s.\00"
@.str.3 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @error_code(i32 -1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %40
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @strchr(i8* dereferenceable(1) %9, i32 58)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %1
%14 = tail call i32 @error_code(i32 -1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %40
15: ; preds = %7
%16 = icmp ugt i32 %0, 2
br i1 %16, label %17, label %37
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 2
br label %19
19: ; preds = %33, %17
%20 = phi i8* [ null, %17 ], [ %24, %33 ]
%21 = phi i8** [ %18, %17 ], [ %34, %33 ]
%22 = phi i64 [ 0, %17 ], [ %23, %33 ]
%23 = add i64 %22, 256
%24 = tail call i8* @realloc(i8* %20, i64 %23)
%25 = icmp eq i64 %22, 0
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i8*, i8** %21
%28 = tail call i32 @strcpy(i8* %24, i8* %27)
br label %33
29: ; preds = %19
%30 = tail call i32 @strcat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = load i8*, i8** %21
%32 = tail call i32 @strcat(i8* %24, i8* %31)
br label %33
33: ; preds = %26, %29
%34 = getelementptr inbounds i8*, i8** %21, i64 1
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %19
37: ; preds = %33, %15
%38 = phi i8* [ null, %15 ], [ %24, %33 ]
%39 = tail call i32 @mod_find_ps(i8* %9, i8* %38, i32* null)
br label %40
40: ; preds = %37, %12, %4
%41 = phi i32 [ %6, %4 ], [ %39, %37 ], [ %14, %12 ]
ret i32 %41
}