#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *parseInt(char *, int *);
char *parseString(char *s, char **sp) {
  int i;
  char *c;
  s = parseInt(s, &i);
  c = (char *)malloc((i + 1) * sizeof(char));
  while (*s++ != '-')
    ;
  memcpy(c, s, i);
  c[i] = '\0';
  *sp = c;
  return (s + i);
}


x86 assembly (clang, -O0):
<parseString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <parseInt@plt>
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1188 <parseString+0x58>
jmp    1168 <parseString+0x38>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseString>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
lea    0xc(%rsp),%rsi
call   1030 <parseInt@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
nopl   0x0(%rax,%rax,1)
cmpb   $0x2d,(%rbx)
lea    0x1(%rbx),%rbx
jne    1160 <parseString+0x30>
mov    0xc(%rsp),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <memcpy@plt>
movslq 0xc(%rsp),%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,(%r14)
movslq 0xc(%rsp),%rax
add    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @parseString(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8** %1, i8*** %4
%7 = load i8*, i8** %3
%8 = call i8* @parseInt(i8* %7, i32* %5)
store i8* %8, i8** %3
%9 = load i32, i32* %5
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
br label %16
16: ; preds = %22, %2
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
%19 = load i8, i8* %17
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 45
br i1 %21, label %22, label %23
22: ; preds = %16
br label %16
23: ; preds = %16
%24 = load i8*, i8** %6
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = call i32 @memcpy(i8* %24, i8* %25, i32 %26)
%28 = load i8*, i8** %6
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %6
%33 = load i8**, i8*** %4
store i8* %32, i8** %33
%34 = load i8*, i8** %3
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
ret i8* %37
}

LLVM IR (-O2):
define i8* @parseString(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i8* @parseInt(i8* %0, i32* %3)
%6 = load i32, i32* %3
%7 = add nsw i32 %6, 1
%8 = call i64 @malloc(i32 %7)
br label %9
9: ; preds = %9, %2
%10 = phi i8* [ %5, %2 ], [ %11, %9 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 45
br i1 %13, label %14, label %9
14: ; preds = %9
%15 = inttoptr i64 %8 to i8*
%16 = load i32, i32* %3
%17 = call i32 @memcpy(i8* %15, i8* %11, i32 %16)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
store i8 0, i8* %20
store i8* %15, i8** %1
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %11, i64 %22
ret i8* %23
}