#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*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strdup(char *);
int /*<<< orphan*/ *strtok(char *, char *);
int TruncateNames(char **names, int N) {
  int idx;
  char newname[32];
  for (idx = 0; idx < N; idx++)
    if (names[idx] == NULL || strtok(names[idx], " \t\n") == NULL) {
      (void)sprintf(newname, "%d", idx);
      if (names[idx] != NULL)
        free(names[idx]);
      names[idx] = strdup(newname);
    }
  return 1;
}


x86 assembly (clang, -O0):
<TruncateNames>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f9 <TruncateNames+0xb9>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1197 <TruncateNames+0x57>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe78(%rip),%rsi
call   1040 <strtok@plt>
cmp    $0x0,%rax
jne    11e6 <TruncateNames+0xa6>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe5f(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11ce <TruncateNames+0x8e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
lea    -0x30(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11eb <TruncateNames+0xab>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <TruncateNames+0x16>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TruncateNames>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %esi,%esi
jle    11b8 <TruncateNames+0x78>
mov    %rdi,%r14
mov    %esi,%ebp
xor    %ebx,%ebx
lea    0xea4(%rip),%r15
mov    %rsp,%r12
lea    0xe96(%rip),%r13
jmp    1185 <TruncateNames+0x45>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1060 <strdup@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11b8 <TruncateNames+0x78>
mov    (%r14,%rbx,8),%rdi
test   %rdi,%rdi
je     119b <TruncateNames+0x5b>
mov    %r13,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    117c <TruncateNames+0x3c>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <sprintf@plt>
mov    (%r14,%rbx,8),%rdi
test   %rdi,%rdi
je     1170 <TruncateNames+0x30>
call   1030 <free@plt>
jmp    1170 <TruncateNames+0x30>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" \09\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @TruncateNames(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca [32 x i8]
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %51, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %54
11: ; preds = %7
%12 = load i8**, i8*** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %26, label %18
18: ; preds = %11
%19 = load i8**, i8*** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i32* @strtok(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %50
26: ; preds = %18, %11
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i8**, i8*** %3
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %43
36: ; preds = %26
%37 = load i8**, i8*** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %36, %26
%44 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%45 = call i8* @strdup(i8* %44)
%46 = load i8**, i8*** %3
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
store i8* %45, i8** %49
br label %50
50: ; preds = %43, %18
br label %51
51: ; preds = %50
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %7
54: ; preds = %7
ret i32 1
}

LLVM IR (-O2):
@.str = [4 x i8] c" \09\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @TruncateNames(i8** nocapture %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %28
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %25
%9 = phi i64 [ 0, %6 ], [ %26, %25 ]
%10 = getelementptr inbounds i8*, i8** %0, i64 %9
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = tail call i32* @strtok(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %25
16: ; preds = %13, %8
%17 = trunc i64 %9 to i32
%18 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %10
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = tail call i32 @free(i8* %19)
br label %23
23: ; preds = %21, %16
%24 = call i8* @strdup(i8* %4)
store i8* %24, i8** %10
br label %25
25: ; preds = %13, %23
%26 = add nuw nsw i64 %9, 1
%27 = icmp eq i64 %26, %7
br i1 %27, label %28, label %8
28: ; preds = %25, %2
ret i32 1
}