#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 *calloc(int, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *skip_whitespace(char const *);
char *read_value(const char *line) {
  int pos = 0;
  char *result;
  line = skip_whitespace(line);
  for (; line[pos] != '\0'; ++pos) {
  }
  result = calloc(pos + 1, sizeof(char));
  memcpy(result, line, pos * sizeof(char));
  result[pos] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<read_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <skip_whitespace@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1178 <read_value+0x48>
jmp    116a <read_value+0x3a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1150 <read_value+0x20>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_value>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1030 <skip_whitespace@plt>
mov    %rax,%r14
mov    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%r14,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1150 <read_value+0x20>
mov    %ebx,%r12d
lea    0x1(%rbx),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @read_value(i8* %0) {
%2 = tail call i8* @skip_whitespace(i8* %0)
br label %3
3: ; preds = %3, %1
%4 = phi i64 [ %8, %3 ], [ 0, %1 ]
%5 = getelementptr inbounds i8, i8* %2, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = add nuw i64 %4, 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = trunc i64 %4 to i32
%11 = and i64 %4, 4294967295
%12 = add nuw nsw i32 %10, 1
%13 = tail call i8* @calloc(i32 %12, i32 1)
%14 = tail call i32 @memcpy(i8* %13, i8* %2, i32 %10)
%15 = getelementptr inbounds i8, i8* %13, i64 %11
store i8 0, i8* %15
ret i8* %13
}