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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ isprint(char);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int write(int, char *, int);
void instruction_count_set_string(const char *str) {
  char buf[32];
  char out_str[128];
  size_t i;
  char c;
  int size;
  if (str == NULL)
    str = "";
  for (i = 0; i < sizeof(buf) - 1; ++i) {
    c = str[i];
    if (!isprint(c))
      break;
    buf[i] = c;
  }
  if (i == 0) {
    snprintf(buf, sizeof(buf), "COUNT");
    i = sizeof("COUNT") + 1;
  } else {
    buf[i] = '\0';
  }
  snprintf(out_str, sizeof(out_str), "%s%s", "name>", buf);
  size = write(197, out_str, sizeof("name>") - 1 + i);
  if (size != sizeof("name>") - 1 + i)
    exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<instruction_count_set_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1165 <instruction_count_set_string+0x25>
lea    0xeaf(%rip),%rax
mov    %rax,-0x8(%rbp)
movq   $0x0,-0xb8(%rbp)
cmpq   $0x1f,-0xb8(%rbp)
1f
jae    11d4 <instruction_count_set_string+0x94>
mov    -0x8(%rbp),%rax
mov    -0xb8(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xb9(%rbp)
movsbl -0xb9(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%eax
jne    11ac <instruction_count_set_string+0x6c>
jmp    11d4 <instruction_count_set_string+0x94>
mov    -0xb9(%rbp),%cl
mov    -0xb8(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0xb8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xb8(%rbp)
jmp    1170 <instruction_count_set_string+0x30>
cmpq   $0x0,-0xb8(%rbp)
jne    1209 <instruction_count_set_string+0xc9>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
lea    0xe0e(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
movq   $0x7,-0xb8(%rbp)
jmp    1215 <instruction_count_set_string+0xd5>
mov    -0xb8(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0xb0(%rbp),%rdi
lea    -0x30(%rbp),%r8
mov    $0x80,%esi
lea    0xdda(%rip),%rdx
lea    0xdd8(%rip),%rcx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0xb0(%rbp),%rsi
mov    -0xb8(%rbp),%rax
add    $0x5,%rax
mov    %eax,%edx
mov    $0xc5,%edi
call   1030 <write@plt>
mov    %eax,-0xc0(%rbp)
movslq -0xc0(%rbp),%rax
mov    -0xb8(%rbp),%rcx
add    $0x5,%rcx
cmp    %rcx,%rax
je     1287 <instruction_count_set_string+0x147>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<instruction_count_set_string>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
test   %rdi,%rdi
lea    0xeba(%rip),%r14
cmovne %rdi,%r14
xor    %r15d,%r15d
nopl   (%rax)
movzbl (%r14,%r15,1),%ebx
movsbl %bl,%edi
call   1050 <isprint@plt>
test   %eax,%eax
je     1187 <instruction_count_set_string+0x47>
mov    %bl,(%rsp,%r15,1)
add    $0x1,%r15
cmp    $0x1f,%r15
jne    1160 <instruction_count_set_string+0x20>
mov    $0x1f,%r15d
jmp    118c <instruction_count_set_string+0x4c>
test   %r15,%r15
je     11de <instruction_count_set_string+0x9e>
movb   $0x0,(%rsp,%r15,1)
lea    0xe6e(%rip),%rdx
lea    0xe6c(%rip),%rcx
lea    0x20(%rsp),%r14
mov    %rsp,%r8
mov    %r14,%rdi
mov    $0x80,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
add    $0x5,%r15
mov    $0xc5,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <write@plt>
cltq
cmp    %rax,%r15
jne    11fc <instruction_count_set_string+0xbc>
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe1b(%rip),%rdx
mov    %rsp,%rdi
mov    $0x20,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    $0x7,%r15d
jmp    1191 <instruction_count_set_string+0x51>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"COUNT\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [6 x i8] c"name>\00"
@EXIT_FAILURE = global i32 0
define void @instruction_count_set_string(i8* %0) {
%2 = alloca i8*
%3 = alloca [32 x i8]
%4 = alloca [128 x i8]
%5 = alloca i64
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %11
11: ; preds = %10, %1
store i64 0, i64* %5
br label %12
12: ; preds = %28, %11
%13 = load i64, i64* %5
%14 = icmp ult i64 %13, 31
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = load i8*, i8** %2
%17 = load i64, i64* %5
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
store i8 %19, i8* %6
%20 = load i8, i8* %6
%21 = call i32 @isprint(i8 signext %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %15
br label %31
24: ; preds = %15
%25 = load i8, i8* %6
%26 = load i64, i64* %5
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %26
store i8 %25, i8* %27
br label %28
28: ; preds = %24
%29 = load i64, i64* %5
%30 = add i64 %29, 1
store i64 %30, i64* %5
br label %12
31: ; preds = %23, %12
%32 = load i64, i64* %5
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%36 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %35, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i64 7, i64* %5
br label %40
37: ; preds = %31
%38 = load i64, i64* %5
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %37, %34
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%43 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %41, i32 128, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%45 = load i64, i64* %5
%46 = add i64 5, %45
%47 = trunc i64 %46 to i32
%48 = call i32 @write(i32 197, i8* %44, i32 %47)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = load i64, i64* %5
%52 = add i64 5, %51
%53 = icmp ne i64 %50, %52
br i1 %53, label %54, label %57
54: ; preds = %40
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %40
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"COUNT\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [6 x i8] c"name>\00"
@EXIT_FAILURE = global i32 0
define void @instruction_count_set_string(i8* %0) {
%2 = alloca [32 x i8]
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
br label %8
8: ; preds = %1, %14
%9 = phi i64 [ 0, %1 ], [ %16, %14 ]
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @isprint(i8 signext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %9
store i8 %11, i8* %15
%16 = add nuw nsw i64 %9, 1
%17 = icmp eq i64 %16, 31
br i1 %17, label %22, label %8
18: ; preds = %8
%19 = icmp eq i64 %9, 0
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %25
22: ; preds = %14, %18
%23 = phi i64 [ %9, %18 ], [ 31, %14 ]
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %22, %20
%26 = phi i64 [ 7, %20 ], [ %23, %22 ]
%27 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %5, i32 128, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%28 = add nuw i64 %26, 5
%29 = trunc i64 %28 to i32
%30 = call i32 @write(i32 197, i8* %5, i32 %29)
%31 = sext i32 %30 to i64
%32 = icmp eq i64 %28, %31
br i1 %32, label %36, label %33
33: ; preds = %25
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %25
ret void
}