#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 */
typedef int /*<<< orphan*/ lcopy;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pl_trace_base_add_string_tag(char *, int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void pl_trace_base_add_string_tag_full(char *str_p) {
  int len = strlen(str_p);
  if (len < (2)) {
    printf("pl_trace_base: Tag too short, has to be at least of size %d\n",
           (2));
    exit(1);
  }
  if (len >= (12)) {
    printf("pl_trace_base: Tag too long, has to be shorter than %d\n", (12));
    exit(1);
  }
  if (str_p[len - 2] == ':') {
    char lcopy[(12)];
    int level;
    memset(lcopy, 0, sizeof(lcopy));
    strncpy(lcopy, str_p, sizeof(lcopy) - 1);
    lcopy[len - 2] = '\0';
    level = atoi((char *)&lcopy[len - 1]);
    if (!(level <= (4) && level >= (1))) {
      printf("pl_trace_base: Level %d not supported\n", level);
      exit(1);
    }
    pl_trace_base_add_string_tag(lcopy, level);
  } else {
    pl_trace_base_add_string_tag(str_p, 1);
  }
}


x86 assembly (clang, -O0):
<pl_trace_base_add_string_tag_full>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    11ad <pl_trace_base_add_string_tag_full+0x3d>
lea    0xe67(%rip),%rdi
mov    $0x2,%esi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0xc,-0xc(%rbp)
jl     11d2 <pl_trace_base_add_string_tag_full+0x62>
lea    0xe7f(%rip),%rdi
mov    $0xc,%esi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    1270 <pl_trace_base_add_string_tag_full+0x100>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
lea    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xb,%edx
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0x18(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
lea    -0x18(%rbp),%rdi
add    %rax,%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jg     1246 <pl_trace_base_add_string_tag_full+0xd6>
cmpl   $0x1,-0x1c(%rbp)
jge    125f <pl_trace_base_add_string_tag_full+0xef>
mov    -0x1c(%rbp),%esi
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <pl_trace_base_add_string_tag@plt>
jmp    127e <pl_trace_base_add_string_tag_full+0x10e>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1070 <pl_trace_base_add_string_tag@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pl_trace_base_add_string_tag_full>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1040 <strlen@plt>
cmp    $0x1,%eax
jle    1216 <pl_trace_base_add_string_tag_full+0xa6>
mov    %eax,%ebx
cmp    $0xc,%eax
jae    1224 <pl_trace_base_add_string_tag_full+0xb4>
lea    -0x2(%rbx),%r12d
cmpb   $0x3a,(%r14,%r12,1)
jne    11fe <pl_trace_base_add_string_tag_full+0x8e>
lea    0xc(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xb,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xc(%rsp,%r12,1)
add    $0xffffffff,%ebx
lea    (%rsp,%rbx,1),%rdi
add    $0xc,%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
cmp    $0x4,%ecx
jae    1232 <pl_trace_base_add_string_tag_full+0xc2>
lea    0xc(%rsp),%rdi
mov    %eax,%esi
call   1070 <pl_trace_base_add_string_tag@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
mov    $0x1,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <pl_trace_base_add_string_tag@plt>
lea    0xde3(%rip),%rdi
mov    $0x2,%esi
jmp    123b <pl_trace_base_add_string_tag_full+0xcb>
lea    0xe12(%rip),%rdi
mov    $0xc,%esi
jmp    123b <pl_trace_base_add_string_tag_full+0xcb>
lea    0xe3c(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [61 x i8] c"pl_trace_base: Tag too short, has to be at least of size %d\0A\00"
@.str.1 = [56 x i8] c"pl_trace_base: Tag too long, has to be shorter than %d\0A\00"
@.str.2 = [39 x i8] c"pl_trace_base: Level %d not supported\0A\00"
define void @pl_trace_base_add_string_tag_full(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [12 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 2)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 12
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 12)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 58
br i1 %27, label %28, label %56
28: ; preds = %19
%29 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 12)
%31 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%32 = load i8*, i8** %2
%33 = call i32 @strncpy(i8* %31, i8* %32, i32 11)
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 %36
store i8 0, i8* %37
%38 = load i32, i32* %3
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 %40
%42 = call i32 @atoi(i8* %41)
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = icmp sle i32 %43, 4
br i1 %44, label %45, label %48
45: ; preds = %28
%46 = load i32, i32* %5
%47 = icmp sge i32 %46, 1
br i1 %47, label %52, label %48
48: ; preds = %45, %28
%49 = load i32, i32* %5
%50 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %45
%53 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%54 = load i32, i32* %5
%55 = call i32 @pl_trace_base_add_string_tag(i8* %53, i32 %54)
br label %59
56: ; preds = %19
%57 = load i8*, i8** %2
%58 = call i32 @pl_trace_base_add_string_tag(i8* %57, i32 1)
br label %59
59: ; preds = %56, %52
ret void
}

LLVM IR (-O2):
@.str = [61 x i8] c"pl_trace_base: Tag too short, has to be at least of size %d\0A\00"
@.str.1 = [56 x i8] c"pl_trace_base: Tag too long, has to be shorter than %d\0A\00"
@.str.2 = [39 x i8] c"pl_trace_base: Level %d not supported\0A\00"
define void @pl_trace_base_add_string_tag_full(i8* %0) {
%2 = alloca [12 x i8]
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp slt i32 %3, 2
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 2)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = icmp ugt i32 %3, 11
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 12)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %8
%14 = add nsw i32 %3, -2
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 58
br i1 %18, label %19, label %35
19: ; preds = %13
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 12)
%22 = call i32 @strncpy(i8* %20, i8* %0, i32 11)
%23 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 %15
store i8 0, i8* %23
%24 = add nsw i32 %3, -1
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 %25
%27 = call i32 @atoi(i8* %26)
%28 = add i32 %27, -1
%29 = icmp ult i32 %28, 4
br i1 %29, label %33, label %30
30: ; preds = %19
%31 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %19
%34 = call i32 @pl_trace_base_add_string_tag(i8* %20, i32 %27)
br label %37
35: ; preds = %13
%36 = tail call i32 @pl_trace_base_add_string_tag(i8* %0, i32 1)
br label %37
37: ; preds = %35, %33
ret void
}