#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 */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
char *getPluralChar(float number, char *unit) {
  int length = (int)strlen(unit);
  char *retUnit = malloc((length + 2) * sizeof(char));
  if ((int)(number + 0.5) > 1) {
    sprintf(retUnit, "%ss", unit);
    return retUnit;
  } else {
    sprintf(retUnit, "%s", unit);
    return retUnit;
  }
}


x86 assembly (clang, -O0):
<getPluralChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0xc(%rbp)
mov    %rdi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe8b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cmp    $0x1,%eax
jle    11a7 <getPluralChar+0x77>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe73(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c3 <getPluralChar+0x93>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPluralChar>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movss  %xmm0,0x4(%rsp)
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   1050 <malloc@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe94(%rip),%xmm0
mov    %rax,%rbx
cvttsd2si %xmm0,%eax
cmp    $0x2,%eax
jl     118c <getPluralChar+0x4c>
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <sprintf@plt>
jmp    1197 <getPluralChar+0x57>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ss\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @getPluralChar(float %0, i8* %1) {
%3 = alloca i8*
%4 = alloca float
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store float %0, float* %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %7
%17 = load float, float* %4
%18 = fpext float %17 to double
%19 = fadd double %18, 5.000000e-01
%20 = fptosi double %19 to i32
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = load i8*, i8** %7
%24 = load i8*, i8** %5
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %7
store i8* %26, i8** %3
br label %32
27: ; preds = %2
%28 = load i8*, i8** %7
%29 = load i8*, i8** %5
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %7
store i8* %31, i8** %3
br label %32
32: ; preds = %27, %22
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ss\00"
define i8* @getPluralChar(float %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = add nsw i32 %4, 2
%6 = tail call i8* @malloc(i32 %5)
%7 = fpext float %0 to double
%8 = fadd double %7, 5.000000e-01
%9 = fptosi double %8 to i32
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %15
13: ; preds = %2
%14 = tail call i8* @strcpy(i8* dereferenceable(1) %6, i8* dereferenceable(1) %1)
br label %15
15: ; preds = %13, %11
ret i8* %6
}