#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 atoi(char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *ddt_toc(char *s, int r) {
  int k;
  char t[8];
  static char v[8];
  *v = 0;
  if (r > 7)
    r = 7;
  strncpy(t, s, (size_t)r);
  t[r] = 0;
  if (*t == 'N')
    strcpy(v, "N");
  if (*t == 'O')
    strcpy(v, "O");
  if (*t == 'P')
    strcpy(v, "P");
  if (isdigit(*t) || *t == '-') {
    k = atoi(t);
    if (k < 0)
      sprintf(v, "i%i", -k);
    else
      sprintf(v, "r%i", k);
  }
  return v;
}


x86 assembly (clang, -O0):
<ddt_toc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,0x2ee3(%rip)
cmpl   $0x7,-0xc(%rbp)
jle    1177 <ddt_toc+0x27>
movl   $0x7,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rdx
call   1030 <strncpy@plt>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x18(%rbp,%rax,1)
movsbl -0x18(%rbp),%eax
cmp    $0x4e,%eax
jne    11b1 <ddt_toc+0x61>
lea    0x2ea4(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1050 <strcpy@plt>
movsbl -0x18(%rbp),%eax
cmp    $0x4f,%eax
jne    11d1 <ddt_toc+0x81>
lea    0x2e84(%rip),%rdi
lea    0xe36(%rip),%rsi
call   1050 <strcpy@plt>
movsbl -0x18(%rbp),%eax
cmp    $0x50,%eax
jne    11f1 <ddt_toc+0xa1>
lea    0x2e64(%rip),%rdi
lea    0xe18(%rip),%rsi
call   1050 <strcpy@plt>
movsbl -0x18(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
jne    1211 <ddt_toc+0xc1>
movsbl -0x18(%rbp),%eax
cmp    $0x2d,%eax
jne    125f <ddt_toc+0x10f>
lea    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1244 <ddt_toc+0xf4>
xor    %edx,%edx
sub    -0x10(%rbp),%edx
lea    0x2e16(%rip),%rdi
lea    0xdcc(%rip),%rsi
call   1070 <sprintf@plt>
jmp    125a <ddt_toc+0x10a>
mov    -0x10(%rbp),%edx
lea    0x2dfb(%rip),%rdi
lea    0xdb5(%rip),%rsi
call   1070 <sprintf@plt>
jmp    125f <ddt_toc+0x10f>
lea    0x2de3(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ddt_toc>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rax
movb   $0x0,0x2eea(%rip)
cmp    $0x7,%esi
mov    $0x7,%ecx
cmovl  %esi,%ecx
movslq %ecx,%rbx
lea    0x8(%rsp),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,0x8(%rsp,%rbx,1)
mov    0x8(%rsp),%al
cmp    $0x4e,%al
je     11db <ddt_toc+0x8b>
cmp    $0x4f,%al
je     11f6 <ddt_toc+0xa6>
cmp    $0x50,%al
jne    11a9 <ddt_toc+0x59>
lea    0x2eb0(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1050 <strcpy@plt>
mov    0x8(%rsp),%al
movsbl %al,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
jne    11bd <ddt_toc+0x6d>
cmpb   $0x2d,0x8(%rsp)
jne    122a <ddt_toc+0xda>
lea    0x8(%rsp),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
js     1213 <ddt_toc+0xc3>
lea    0x2e77(%rip),%rdi
lea    0xe31(%rip),%rsi
jmp    1223 <ddt_toc+0xd3>
lea    0x2e67(%rip),%rdi
lea    0xe17(%rip),%rsi
call   1050 <strcpy@plt>
mov    0x8(%rsp),%al
cmp    $0x4f,%al
jne    118e <ddt_toc+0x3e>
lea    0x2e4c(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   1050 <strcpy@plt>
mov    0x8(%rsp),%al
cmp    $0x50,%al
je     1192 <ddt_toc+0x42>
jmp    11a9 <ddt_toc+0x59>
neg    %eax
lea    0x2e2d(%rip),%rdi
lea    0xde3(%rip),%rsi
mov    %eax,%edx
call   1070 <sprintf@plt>
lea    0x2e18(%rip),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ddt_toc.v = internal global [8 x i8] zeroinitializer
@.str = [2 x i8] c"N\00"
@.str.1 = [2 x i8] c"O\00"
@.str.2 = [2 x i8] c"P\00"
@.str.3 = [4 x i8] c"i%i\00"
@.str.4 = [4 x i8] c"r%i\00"
define i8* @ddt_toc(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0)
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 7
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 7, i32* %4
br label %10
10: ; preds = %9, %2
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = call i32 @strncpy(i8* %11, i8* %12, i64 %14)
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 78
br i1 %22, label %23, label %25
23: ; preds = %10
%24 = call i32 @strcpy(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %10
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 79
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @strcpy(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 80
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @strcpy(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %32
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%41 = load i8, i8* %40
%42 = call i64 @isdigit(i8 signext %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %39
%45 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 45
br i1 %48, label %49, label %62
49: ; preds = %44, %39
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%51 = call i32 @atoi(i8* %50)
store i32 %51, i32* %5
%52 = load i32, i32* %5
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load i32, i32* %5
%56 = sub nsw i32 0, %55
%57 = call i32 @sprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %56)
br label %61
58: ; preds = %49
%59 = load i32, i32* %5
%60 = call i32 @sprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %58, %54
br label %62
62: ; preds = %61, %44
ret i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0)
}

LLVM IR (-O2):
@ddt_toc.v = internal global [8 x i8] zeroinitializer
@.str = [2 x i8] c"N\00"
@.str.1 = [2 x i8] c"O\00"
@.str.2 = [2 x i8] c"P\00"
@.str.3 = [4 x i8] c"i%i\00"
@.str.4 = [4 x i8] c"r%i\00"
define i8* @ddt_toc(i8* %0, i32 %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
store i8 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0)
%5 = icmp slt i32 %1, 7
%6 = select i1 %5, i32 %1, i32 7
%7 = sext i32 %6 to i64
%8 = call i32 @strncpy(i8* %4, i8* %0, i64 %7)
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %7
store i8 0, i8* %9
%10 = load i8, i8* %4
%11 = icmp eq i8 %10, 78
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @strcpy(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = load i8, i8* %4
br label %15
15: ; preds = %12, %2
%16 = phi i8 [ %14, %12 ], [ %10, %2 ]
%17 = icmp eq i8 %16, 79
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @strcpy(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8, i8* %4
br label %21
21: ; preds = %18, %15
%22 = phi i8 [ %20, %18 ], [ %16, %15 ]
%23 = icmp eq i8 %22, 80
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = call i32 @strcpy(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = load i8, i8* %4
br label %27
27: ; preds = %24, %21
%28 = phi i8 [ %26, %24 ], [ %22, %21 ]
%29 = call i64 @isdigit(i8 signext %28)
%30 = icmp ne i64 %29, 0
%31 = load i8, i8* %4
%32 = icmp eq i8 %31, 45
%33 = select i1 %30, i1 true, i1 %32
br i1 %33, label %34, label %42
34: ; preds = %27
%35 = call i32 @atoi(i8* %4)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = sub nsw i32 0, %35
%39 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %38)
br label %42
40: ; preds = %34
%41 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %42
42: ; preds = %37, %40, %27
ret i8* getelementptr inbounds ([8 x i8], [8 x i8]* @ddt_toc.v, i64 0, i64 0)
}