#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*/ double_string(char **);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int main() {
  int max = 1000;
  char *in_string = (char *)malloc(2);
  *in_string = 1 + 48;
  *(in_string + 1) = 0;
  int i;
  for (i = 0; i < max; ++i)
    double_string(&in_string);
  int sum = 0;
  for (i = 0; i < strlen(in_string); ++i)
    sum += *(in_string + i) - 48;
  printf("%d\n", sum);
  free(in_string);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
mov    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x31,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ad <main+0x5d>
lea    -0x10(%rbp),%rdi
call   1060 <double_string@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118a <main+0x3a>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11fa <main+0xaa>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <main+0x6b>
mov    -0x18(%rbp),%esi
lea    0xdfc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
movb   $0x31,(%rax)
mov    0x8(%rsp),%rax
movb   $0x0,0x1(%rax)
mov    $0x3e8,%ebp
lea    0x8(%rsp),%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <double_string@plt>
add    $0xffffffff,%ebp
jne    1180 <main+0x30>
mov    0x8(%rsp),%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c2 <main+0x72>
xor    %ebx,%ebx
xor    %r14d,%r14d
mov    0x8(%rsp),%rdi
movsbl (%rdi,%rbx,1),%eax
add    %eax,%r14d
add    $0xffffffd0,%r14d
add    $0x1,%rbx
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11a0 <main+0x50>
jmp    11c5 <main+0x75>
xor    %r14d,%r14d
lea    0xe34(%rip),%rdi
mov    %r14d,%esi
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1000, i32* %2
%6 = call i64 @malloc(i32 2)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i8*, i8** %3
store i8 49, i8* %8
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 0, i8* %10
store i32 0, i32* %4
br label %11
11: ; preds = %17, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = call i32 @double_string(i8** %3)
br label %17
17: ; preds = %15
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %11
20: ; preds = %11
store i32 0, i32* %5
store i32 0, i32* %4
br label %21
21: ; preds = %36, %20
%22 = load i32, i32* %4
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %39
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = sub nsw i32 %32, 48
%34 = load i32, i32* %5
%35 = add nsw i32 %34, %33
store i32 %35, i32* %5
br label %36
36: ; preds = %26
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %21
39: ; preds = %21
%40 = load i32, i32* %5
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i8*, i8** %3
%43 = call i32 @free(i8* %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i64 @malloc(i32 2)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %1
store i8 49, i8* %4
%5 = load i8*, i8** %1
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8 0, i8* %6
br label %11
7: ; preds = %11
%8 = load i8*, i8** %1
%9 = call i32 @strlen(i8* %8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %16, label %29
11: ; preds = %0, %11
%12 = phi i32 [ 0, %0 ], [ %14, %11 ]
%13 = call i32 @double_string(i8** %1)
%14 = add nuw nsw i32 %12, 1
%15 = icmp eq i32 %14, 1000
br i1 %15, label %7, label %11
16: ; preds = %7, %16
%17 = phi i64 [ %25, %16 ], [ 0, %7 ]
%18 = phi i32 [ %24, %16 ], [ 0, %7 ]
%19 = load i8*, i8** %1
%20 = getelementptr inbounds i8, i8* %19, i64 %17
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = add i32 %18, -48
%24 = add i32 %23, %22
%25 = add nuw nsw i64 %17, 1
%26 = call i32 @strlen(i8* %19)
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %16, label %29
29: ; preds = %16, %7
%30 = phi i32 [ 0, %7 ], [ %24, %16 ]
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i8*, i8** %1
%33 = call i32 @free(i8* %32)
ret i32 0
}