#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 atoi(unsigned char *);
void *readChar();
int readInt(void) {
  unsigned char buffer[100];
  char cara = 0;
  int rx_length = 0, data;
  char *pch;
  buffer[rx_length] = 0;
  while (cara != '$') {
    cara = readChar();
  }
  while (cara != '\n') {
    buffer[rx_length] = readChar();
    cara = buffer[rx_length];
    rx_length++;
  }
  data = atoi(buffer);
  return data;
}


x86 assembly (clang, -O0):
<readInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movb   $0x0,-0x71(%rbp)
movl   $0x0,-0x78(%rbp)
movslq -0x78(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
movsbl -0x71(%rbp),%eax
cmp    $0x24,%eax
je     115b <readInt+0x3b>
mov    $0x0,%al
call   1030 <readChar@plt>
mov    %al,-0x71(%rbp)
jmp    113f <readInt+0x1f>
jmp    1160 <readInt+0x40>
movsbl -0x71(%rbp),%eax
cmp    $0xa,%eax
je     1197 <readInt+0x77>
mov    $0x0,%al
call   1030 <readChar@plt>
mov    %al,%cl
movslq -0x78(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
movslq -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x71(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1160 <readInt+0x40>
lea    -0x70(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readInt>:
push   %rbx
sub    $0x70,%rsp
movb   $0x0,(%rsp)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <readChar@plt>
cmp    $0x24,%al
jne    1130 <readInt+0x10>
mov    %rsp,%rbx
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <readChar@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1140 <readInt+0x20>
mov    %rsp,%rdi
call   1040 <atoi@plt>
add    $0x70,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @readInt() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8 0, i8* %2
br label %3
3: ; preds = %0, %3
%4 = tail call i8* (...) @readChar()
%5 = ptrtoint i8* %4 to i64
%6 = trunc i64 %5 to i8
%7 = icmp eq i8 %6, 36
br i1 %7, label %8, label %3
8: ; preds = %3, %8
%9 = phi i64 [ %14, %8 ], [ 0, %3 ]
%10 = tail call i8* (...) @readChar()
%11 = ptrtoint i8* %10 to i64
%12 = trunc i64 %11 to i8
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %9
store i8 %12, i8* %13
%14 = add nuw i64 %9, 1
%15 = icmp eq i8 %12, 10
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = call i32 @atoi(i8* %2)
ret i32 %17
}