#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 *);
char *malloc(size_t);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *changeStrIfMinusIsFirst(char *str) {
  if (*str == '-') {
    size_t len = strlen(str);
    char *nstr = malloc(len + 1);
    *nstr = '0';
    strncpy(nstr + 1, str, len);
    free(str);
    return nstr;
  }
  return str;
}


x86 assembly (clang, -O0):
<changeStrIfMinusIsFirst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11ac <changeStrIfMinusIsFirst+0x6c>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b4 <changeStrIfMinusIsFirst+0x74>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeStrIfMinusIsFirst>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
cmpb   $0x2d,(%rdi)
jne    1181 <changeStrIfMinusIsFirst+0x41>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%r14
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
movb   $0x30,(%rax)
lea    0x1(%rax),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @changeStrIfMinusIsFirst(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 45
br i1 %9, label %10, label %25
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = add i64 %13, 1
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
store i8 48, i8* %16
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8*, i8** %3
%20 = load i64, i64* %4
%21 = call i32 @strncpy(i8* %18, i8* %19, i64 %20)
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
%24 = load i8*, i8** %5
store i8* %24, i8** %2
br label %27
25: ; preds = %1
%26 = load i8*, i8** %3
store i8* %26, i8** %2
br label %27
27: ; preds = %25, %10
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
define i8* @changeStrIfMinusIsFirst(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 45
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = tail call i64 @strlen(i8* %0)
%6 = add i64 %5, 1
%7 = tail call i8* @malloc(i64 %6)
store i8 48, i8* %7
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = tail call i32 @strncpy(i8* %8, i8* %0, i64 %5)
%10 = tail call i32 @free(i8* %0)
br label %11
11: ; preds = %1, %4
%12 = phi i8* [ %7, %4 ], [ %0, %1 ]
ret i8* %12
}