#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*/ u_int8_t;

/* Variables and functions */
char *names_class(int /*<<< orphan*/);
int snprintf(char *, size_t, char *, char const *);
int get_class_string(char *buf, size_t size, u_int8_t cls) {
  const char *cp;
  if (size < 1)
    return 0;
  *buf = 0;
  if (!(cp = names_class(cls)))
    return 0;
  return snprintf(buf, size, "%s", cp);
}


x86 assembly (clang, -O0):
<get_class_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x1,-0x18(%rbp)
jae    114a <get_class_string+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    118e <get_class_string+0x6e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%edi
call   1030 <names_class@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1173 <get_class_string+0x53>
movl   $0x0,-0x4(%rbp)
jmp    118e <get_class_string+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xe7a(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_class_string>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     115a <get_class_string+0x3a>
mov    %rsi,%rbx
mov    %rdi,%r14
movb   $0x0,(%rdi)
mov    %edx,%edi
call   1030 <names_class@plt>
test   %rax,%rax
je     115a <get_class_string+0x3a>
lea    0xebb(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <snprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @get_class_string(i8* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%9 = load i64, i64* %6
%10 = icmp ult i64 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 0, i32* %4
br label %23
12: ; preds = %3
%13 = load i8*, i8** %5
store i8 0, i8* %13
%14 = load i32, i32* %7
%15 = call i8* @names_class(i32 %14)
store i8* %15, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %12
store i32 0, i32* %4
br label %23
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = load i8*, i8** %8
%22 = call i32 @snprintf(i8* %19, i64 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 %22, i32* %4
br label %23
23: ; preds = %18, %17, %11
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @get_class_string(i8* %0, i64 %1, i32 %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %10, label %5
5: ; preds = %3
store i8 0, i8* %0
%6 = tail call i8* @names_class(i32 %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %10
10: ; preds = %5, %3, %8
%11 = phi i32 [ %9, %8 ], [ 0, %3 ], [ 0, %5 ]
ret i32 %11
}