#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__ EOF;
scalar_t__ getchar_fake();
int /*<<< orphan*/ init_fake_input_to(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, long);
int /*<<< orphan*/ stringShouldEqual(char *, char *);
void part_1_5_2() {
  init_fake_input_to("asdf ghjkl!!\nanother line\nohh!!");
  long nc = 0;
  for (nc = 0; getchar_fake() != EOF; ++nc)
    ;
  char *actual = (char *)malloc(10000);
  sprintf(actual, "%ld\n", nc);
  ;
  stringShouldEqual("31\n", actual);
}


x86 assembly (clang, -O0):
<part_1_5_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1030 <init_fake_input_to@plt>
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getchar_fake@plt>
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
je     11a1 <part_1_5_2+0x51>
jmp    1190 <part_1_5_2+0x40>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1174 <part_1_5_2+0x24>
mov    $0x2710,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe62(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1040 <stringShouldEqual@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<part_1_5_2>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <init_fake_input_to@plt>
mov    $0xffffffffffffffff,%rbx
mov    0x2e7a(%rip),%r14
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar_fake@plt>
add    $0x1,%rbx
cmp    (%r14),%rax
jne    1170 <part_1_5_2+0x20>
mov    $0x2710,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
lea    0xe7f(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <stringShouldEqual@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"asdf ghjkl!!\0Aanother line\0Aohh!!\00"
@EOF = global i64 0
@.str.1 = [5 x i8] c"%ld\0A\00"
@.str.2 = [4 x i8] c"31\0A\00"
define void @part_1_5_2() {
%1 = alloca i64
%2 = alloca i8*
%3 = call i32 @init_fake_input_to(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %1
store i64 0, i64* %1
br label %4
4: ; preds = %9, %0
%5 = call i64 (...) @getchar_fake()
%6 = load i64, i64* @EOF
%7 = icmp ne i64 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %4
br label %9
9: ; preds = %8
%10 = load i64, i64* %1
%11 = add nsw i64 %10, 1
store i64 %11, i64* %1
br label %4
12: ; preds = %4
%13 = call i64 @malloc(i32 10000)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %2
%15 = load i8*, i8** %2
%16 = load i64, i64* %1
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %16)
%18 = load i8*, i8** %2
%19 = call i32 @stringShouldEqual(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %18)
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"asdf ghjkl!!\0Aanother line\0Aohh!!\00"
@EOF = global i64 0
@.str.1 = [5 x i8] c"%ld\0A\00"
@.str.2 = [4 x i8] c"31\0A\00"
define void @part_1_5_2() {
%1 = tail call i32 @init_fake_input_to(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %7, %2 ]
%4 = tail call i64 (...) @getchar_fake()
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
%7 = add nuw nsw i64 %3, 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = tail call i64 @malloc(i32 10000)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %3)
%12 = tail call i32 @stringShouldEqual(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %10)
ret void
}