#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 /*<<< orphan*/ all_numbers(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char const *);
char *strtok(char *, char *);
int validate_container_id(const char *input) {
  int is_container_id = 1;
  if (!input) {
    return 0;
  }
  char *input_cpy = strdup(input);
  if (!input_cpy) {
    return 0;
  }
  char *p = strtok(input_cpy, "_");
  int idx = 0;
  while (p != NULL) {
    if (0 == idx) {
      if (0 != strcmp("container", p)) {
        is_container_id = 0;
        goto cleanup;
      }
    } else if (1 == idx) {
      if (!all_numbers(p)) {
        if (p[0] == 0) {
          is_container_id = 0;
          goto cleanup;
        }
        if (p[0] != 'e') {
          is_container_id = 0;
          goto cleanup;
        }
        if (!all_numbers(p + 1)) {
          is_container_id = 0;
          goto cleanup;
        }
      }
    } else {
      if (!all_numbers(p)) {
        is_container_id = 0;
        goto cleanup;
      }
    }
    p = strtok(NULL, "_");
    idx++;
  }
cleanup:
  if (input_cpy) {
    free(input_cpy);
  }
  if (idx > 6 || idx < 5) {
    is_container_id = 0;
  }
  return is_container_id;
}


x86 assembly (clang, -O0):
<validate_container_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117a <validate_container_id+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    1306 <validate_container_id+0x1b6>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119e <validate_container_id+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    1306 <validate_container_id+0x1b6>
mov    -0x20(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12cc <validate_container_id+0x17c>
xor    %eax,%eax
cmp    -0x2c(%rbp),%eax
jne    11fe <validate_container_id+0xae>
mov    -0x28(%rbp),%rsi
lea    0xe28(%rip),%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11f9 <validate_container_id+0xa9>
movl   $0x0,-0x14(%rbp)
jmp    12d1 <validate_container_id+0x181>
jmp    12aa <validate_container_id+0x15a>
mov    $0x1,%eax
cmp    -0x2c(%rbp),%eax
jne    1282 <validate_container_id+0x132>
mov    -0x28(%rbp),%rdi
call   1040 <all_numbers@plt>
cmp    $0x0,%eax
jne    127d <validate_container_id+0x12d>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    123a <validate_container_id+0xea>
movl   $0x0,-0x14(%rbp)
jmp    12d1 <validate_container_id+0x181>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x65,%eax
je     1256 <validate_container_id+0x106>
movl   $0x0,-0x14(%rbp)
jmp    12d1 <validate_container_id+0x181>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <all_numbers@plt>
cmp    $0x0,%eax
jne    1278 <validate_container_id+0x128>
movl   $0x0,-0x14(%rbp)
jmp    12d1 <validate_container_id+0x181>
jmp    127d <validate_container_id+0x12d>
jmp    12a5 <validate_container_id+0x155>
mov    -0x28(%rbp),%rdi
call   1040 <all_numbers@plt>
cmp    $0x0,%eax
jne    12a0 <validate_container_id+0x150>
movl   $0x0,-0x14(%rbp)
jmp    12d1 <validate_container_id+0x181>
jmp    12a5 <validate_container_id+0x155>
jmp    12aa <validate_container_id+0x15a>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd4b(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b9 <validate_container_id+0x69>
jmp    12d1 <validate_container_id+0x181>
cmpq   $0x0,-0x20(%rbp)
je     12e5 <validate_container_id+0x195>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x6,-0x2c(%rbp)
jg     12f9 <validate_container_id+0x1a9>
cmpl   $0x5,-0x2c(%rbp)
jge    1300 <validate_container_id+0x1b0>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_container_id>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     125b <validate_container_id+0x10b>
call   1070 <strdup@plt>
test   %rax,%rax
je     125b <validate_container_id+0x10b>
mov    %rax,%r14
lea    0xe82(%rip),%rsi
mov    %rax,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     1223 <validate_container_id+0xd3>
mov    %rax,%rbx
xor    %r13d,%r13d
lea    0xe64(%rip),%r12
xor    %ebp,%ebp
mov    $0x1,%r15d
jmp    11d2 <validate_container_id+0x82>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <all_numbers@plt>
test   %eax,%eax
je     1237 <validate_container_id+0xe7>
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
add    $0x1,%r13d
test   %rax,%rax
je     122d <validate_container_id+0xdd>
cmp    $0x1,%r13d
je     1200 <validate_container_id+0xb0>
test   %r13d,%r13d
jne    11b0 <validate_container_id+0x60>
lea    0xe1e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11bc <validate_container_id+0x6c>
jmp    123e <validate_container_id+0xee>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <all_numbers@plt>
test   %eax,%eax
jne    11bc <validate_container_id+0x6c>
cmpb   $0x65,(%rbx)
jne    1243 <validate_container_id+0xf3>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <all_numbers@plt>
test   %eax,%eax
jne    11bc <validate_container_id+0x6c>
jmp    1243 <validate_container_id+0xf3>
xor    %r15d,%r15d
mov    $0x1,%ebp
jmp    1243 <validate_container_id+0xf3>
mov    %r13d,%r15d
mov    $0x1,%ebp
jmp    1243 <validate_container_id+0xf3>
xor    %ebp,%ebp
mov    %r13d,%r15d
jmp    1243 <validate_container_id+0xf3>
xor    %r15d,%r15d
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
add    $0xfffffff9,%r15d
cmp    $0xfffffffe,%r15d
mov    $0x0,%eax
cmovb  %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"_\00"
@.str.1 = [10 x i8] c"container\00"
define i32 @validate_container_id(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 1, i32* %4
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 0, i32* %2
br label %88
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
store i32 0, i32* %2
br label %88
17: ; preds = %11
%18 = load i8*, i8** %5
%19 = call i8* @strtok(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %6
store i32 0, i32* %7
br label %20
20: ; preds = %68, %17
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %72
23: ; preds = %20
%24 = load i32, i32* %7
%25 = icmp eq i32 0, %24
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = icmp ne i64 0, %28
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %4
br label %73
31: ; preds = %26
br label %68
32: ; preds = %23
%33 = load i32, i32* %7
%34 = icmp eq i32 1, %33
br i1 %34, label %35, label %61
35: ; preds = %32
%36 = load i8*, i8** %6
%37 = call i32 @all_numbers(i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %60, label %39
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
store i32 0, i32* %4
br label %73
46: ; preds = %39
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 101
br i1 %51, label %52, label %53
52: ; preds = %46
store i32 0, i32* %4
br label %73
53: ; preds = %46
%54 = load i8*, i8** %6
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = call i32 @all_numbers(i8* %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %59, label %58
58: ; preds = %53
store i32 0, i32* %4
br label %73
59: ; preds = %53
br label %60
60: ; preds = %59, %35
br label %67
61: ; preds = %32
%62 = load i8*, i8** %6
%63 = call i32 @all_numbers(i8* %62)
%64 = icmp ne i32 %63, 0
br i1 %64, label %66, label %65
65: ; preds = %61
store i32 0, i32* %4
br label %73
66: ; preds = %61
br label %67
67: ; preds = %66, %60
br label %68
68: ; preds = %67, %31
%69 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %69, i8** %6
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
br label %20
72: ; preds = %20
br label %73
73: ; preds = %72, %65, %58, %52, %45, %30
%74 = load i8*, i8** %5
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = load i8*, i8** %5
%78 = call i32 @free(i8* %77)
br label %79
79: ; preds = %76, %73
%80 = load i32, i32* %7
%81 = icmp sgt i32 %80, 6
br i1 %81, label %85, label %82
82: ; preds = %79
%83 = load i32, i32* %7
%84 = icmp slt i32 %83, 5
br i1 %84, label %85, label %86
85: ; preds = %82, %79
store i32 0, i32* %4
br label %86
86: ; preds = %85, %82
%87 = load i32, i32* %4
store i32 %87, i32* %2
br label %88
88: ; preds = %86, %16, %10
%89 = load i32, i32* %2
ret i32 %89
}

LLVM IR (-O2):
@.str = [2 x i8] c"_\00"
@.str.1 = [10 x i8] c"container\00"
define i32 @validate_container_id(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %39, label %3
3: ; preds = %1
%4 = tail call i8* @strdup(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %39, label %6
6: ; preds = %3
%7 = tail call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %32, label %9
9: ; preds = %6, %28
%10 = phi i32 [ %30, %28 ], [ 0, %6 ]
%11 = phi i8* [ %29, %28 ], [ %7, %6 ]
switch i32 %10, label %25 [
i32 0, label %12
i32 1, label %15
]
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%14 = icmp eq i64 %13, 0
br i1 %14, label %28, label %32
15: ; preds = %9
%16 = tail call i32 @all_numbers(i8* %11)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i8, i8* %11
%20 = icmp eq i8 %19, 101
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %11, i64 1
%23 = tail call i32 @all_numbers(i8* %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %32, label %28
25: ; preds = %9
%26 = tail call i32 @all_numbers(i8* %11)
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %21, %15, %25, %12
%29 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = add nuw nsw i32 %10, 1
%31 = icmp eq i8* %29, null
br i1 %31, label %32, label %9
32: ; preds = %25, %21, %12, %28, %18, %6
%33 = phi i32 [ 0, %6 ], [ 1, %18 ], [ %30, %28 ], [ 0, %12 ], [ 1, %21 ], [ %10, %25 ]
%34 = phi i32 [ 1, %6 ], [ 0, %18 ], [ 1, %28 ], [ 0, %12 ], [ 0, %21 ], [ 0, %25 ]
%35 = tail call i32 @free(i8* %4)
%36 = add nsw i32 %33, -7
%37 = icmp ult i32 %36, -2
%38 = select i1 %37, i32 0, i32 %34
br label %39
39: ; preds = %32, %3, %1
%40 = phi i32 [ 0, %1 ], [ %38, %32 ], [ 0, %3 ]
ret i32 %40
}