#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 EXIT_SUCCESS;
double atof(char *);
int atoi(char *);
double atol(char *);
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ realloc(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
double strtod(char *, char **);
double strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  char *endptr = NULL;
  char *start;
  char *memblk;
  printf("%f\n", atof("15.5"));
  printf("%d\n", atoi("120"));
  printf("%ld\n", atol("1201234"));
  start = malloc(sizeof(char) * 30);
  strcpy(start, "12 -23   98");
  endptr = start;
  while (start + strlen(start) != endptr) {
    printf("value is %ld\n", strtol(endptr, &endptr, 10));
  }
  strcpy(start, "1.2      -2.3   0.23");
  endptr = start;
  while (start + strlen(start) != endptr) {
    printf("value is %g\n", strtod(endptr, &endptr));
  }
  free(start);
  memblk = calloc(1024, sizeof(int) * 10);
  if (memblk) {
    puts("allocated 1024*4*10 bytes with calloc");
  }
  realloc(memblk, 0);
  puts("freed the space");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe0f(%rip),%rdi
call   1070 <atof@plt>
lea    0xdff(%rip),%rdi
call   1090 <printf@plt>
lea    0xe00(%rip),%rdi
call   10f0 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xdec(%rip),%rdi
call   1090 <printf@plt>
lea    0xde8(%rip),%rdi
call   10e0 <atol@plt>
lea    0xdf9(%rip),%rdi
call   1090 <printf@plt>
mov    $0x1e,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
cmp    -0x18(%rbp),%rax
je     12aa <main+0xda>
mov    -0x18(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   10b0 <strtol@plt>
lea    0xd85(%rip),%rdi
call   1090 <printf@plt>
jmp    1260 <main+0x90>
mov    -0x20(%rbp),%rdi
lea    0xd7e(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
cmp    -0x18(%rbp),%rax
je     1307 <main+0x137>
mov    -0x18(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <strtod@plt>
lea    0xd4b(%rip),%rdi
call   1090 <printf@plt>
jmp    12c2 <main+0xf2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x400,%edi
mov    $0x28,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     133a <main+0x16a>
lea    0xd20(%rip),%rdi
call   1050 <puts@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   10d0 <realloc@plt>
lea    0xd2f(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe4c(%rip),%rdi
call   1070 <atof@plt>
lea    0xe3c(%rip),%rdi
call   1090 <printf@plt>
lea    0xe39(%rip),%rdi
movsd  0xe20(%rip),%xmm0
call   1090 <printf@plt>
lea    0xe3e(%rip),%rdi
call   1090 <printf@plt>
mov    $0x1e,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
lea    0xe10(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1080 <strlen@plt>
test   %eax,%eax
je     125c <main+0xac>
lea    0x8(%rsp),%r14
lea    0xdf7(%rip),%r15
mov    %rbx,%rdi
nopl   (%rax)
mov    %r14,%rsi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %r15,%rdi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
cltq
add    %rbx,%rax
mov    0x8(%rsp),%rdi
cmp    %rdi,%rax
jne    1230 <main+0x80>
lea    0xdcc(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1080 <strlen@plt>
test   %eax,%eax
je     12b7 <main+0x107>
lea    0x8(%rsp),%r14
lea    0xdbc(%rip),%r15
mov    %rbx,%rdi
nopl   0x0(%rax,%rax,1)
mov    %r14,%rsi
call   1060 <strtod@plt>
mov    %r15,%rdi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
cltq
add    %rbx,%rax
mov    0x8(%rsp),%rdi
cmp    %rdi,%rax
jne    1290 <main+0xe0>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x400,%edi
mov    $0x28,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12e2 <main+0x132>
lea    0xd74(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   10d0 <realloc@plt>
lea    0xd84(%rip),%rdi
call   1050 <puts@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%f\0A\00"
@.str.1 = [5 x i8] c"15.5\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [4 x i8] c"120\00"
@.str.4 = [5 x i8] c"%ld\0A\00"
@.str.5 = [8 x i8] c"1201234\00"
@.str.6 = [12 x i8] c"12 -23 98\00"
@.str.7 = [14 x i8] c"value is %ld\0A\00"
@.str.8 = [21 x i8] c"1.2 -2.3 0.23\00"
@.str.9 = [13 x i8] c"value is %g\0A\00"
@.str.10 = [38 x i8] c"allocated 1024*4*10 bytes with calloc\00"
@.str.11 = [16 x i8] c"freed the space\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%9 = call double @atof(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %9)
%11 = call i32 @atoi(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%12 = sitofp i32 %11 to double
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %12)
%14 = call double @atol(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), double %14)
%16 = call i8* @malloc(i32 30)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%19 = load i8*, i8** %7
store i8* %19, i8** %6
br label %20
20: ; preds = %28, %2
%21 = load i8*, i8** %7
%22 = load i8*, i8** %7
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8*, i8** %6
%27 = icmp ne i8* %25, %26
br i1 %27, label %28, label %32
28: ; preds = %20
%29 = load i8*, i8** %6
%30 = call double @strtol(i8* %29, i8** %6, i32 10)
%31 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), double %30)
br label %20
32: ; preds = %20
%33 = load i8*, i8** %7
%34 = call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%35 = load i8*, i8** %7
store i8* %35, i8** %6
br label %36
36: ; preds = %44, %32
%37 = load i8*, i8** %7
%38 = load i8*, i8** %7
%39 = call i32 @strlen(i8* %38)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = load i8*, i8** %6
%43 = icmp ne i8* %41, %42
br i1 %43, label %44, label %48
44: ; preds = %36
%45 = load i8*, i8** %6
%46 = call double @strtod(i8* %45, i8** %6)
%47 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), double %46)
br label %36
48: ; preds = %36
%49 = load i8*, i8** %7
%50 = call i32 @free(i8* %49)
%51 = call i8* @calloc(i32 1024, i32 40)
store i8* %51, i8** %8
%52 = load i8*, i8** %8
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.10, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
%57 = load i8*, i8** %8
%58 = call i32 @realloc(i8* %57, i32 0)
%59 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%60 = load i32, i32* @EXIT_SUCCESS
ret i32 %60
}

LLVM IR (-O2):
@.str = [4 x i8] c"%f\0A\00"
@.str.1 = [5 x i8] c"15.5\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.4 = [5 x i8] c"%ld\0A\00"
@.str.6 = [12 x i8] c"12 -23 98\00"
@.str.7 = [14 x i8] c"value is %ld\0A\00"
@.str.8 = [21 x i8] c"1.2 -2.3 0.23\00"
@.str.9 = [13 x i8] c"value is %g\0A\00"
@.str.10 = [38 x i8] c"allocated 1024*4*10 bytes with calloc\00"
@.str.11 = [16 x i8] c"freed the space\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call double @atof(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double 1.200000e+02)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i0 0)
%9 = tail call dereferenceable_or_null(30) i8* @malloc(i32 30)
%10 = tail call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
store i8* %9, i8** %3
%11 = tail call i32 @strlen(i8* %9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %2, %13
%14 = phi i8* [ %20, %13 ], [ %9, %2 ]
%15 = call double @strtol(i8* %14, i8** %3, i32 10)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), double %15)
%17 = tail call i32 @strlen(i8* %9)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %9, i64 %18
%20 = load i8*, i8** %3
%21 = icmp eq i8* %19, %20
br i1 %21, label %22, label %13
22: ; preds = %13, %2
%23 = tail call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
store i8* %9, i8** %3
%24 = tail call i32 @strlen(i8* %9)
%25 = icmp eq i32 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %22, %26
%27 = phi i8* [ %33, %26 ], [ %9, %22 ]
%28 = call double @strtod(i8* %27, i8** %3)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), double %28)
%30 = tail call i32 @strlen(i8* %9)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %9, i64 %31
%33 = load i8*, i8** %3
%34 = icmp eq i8* %32, %33
br i1 %34, label %35, label %26
35: ; preds = %26, %22
%36 = tail call i32 @free(i8* %9)
%37 = tail call dereferenceable_or_null(40960) i8* @calloc(i32 1024, i32 40)
%38 = icmp eq i8* %37, null
br i1 %38, label %41, label %39
39: ; preds = %35
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.10, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
%42 = tail call i32 @realloc(i8* %37, i32 0)
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%44 = load i32, i32* @EXIT_SUCCESS
ret i32 %44
}