#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 EOF;
int getchar();
void read_input(char vet[], int size) {
  int c, i;
  for (i = 0; i < (size - 1) && (c = getchar()) != EOF; ++i)
    vet[i] = c;
  vet[i] = '\0';
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x15(%rbp)
jge    1155 <read_input+0x45>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e9b(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1165 <read_input+0x55>
jmp    1183 <read_input+0x73>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <read_input+0x16>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
xor    %ebp,%ebp
cmp    $0x2,%esi
jl     115d <read_input+0x4d>
mov    %esi,%r14d
add    $0xffffffff,%r14d
mov    %r14d,%ebx
mov    0x2eb5(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    (%r12),%eax
je     115d <read_input+0x4d>
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1140 <read_input+0x30>
mov    %r14d,%ebp
mov    %ebp,%eax
movb   $0x0,(%r15,%rax,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @read_input(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
br label %7
7: ; preds = %25, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = call i32 (...) @getchar()
store i32 %13, i32* %5
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br label %16
16: ; preds = %12, %7
%17 = phi i1 [ false, %7 ], [ %15, %12 ]
br i1 %17, label %18, label %28
18: ; preds = %16
%19 = load i32, i32* %5
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 %20, i8* %24
br label %25
25: ; preds = %18
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %7
28: ; preds = %16
%29 = load i8*, i8** %3
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @read_input(i8* nocapture writeonly %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %12
%8 = phi i64 [ 0, %5 ], [ %15, %12 ]
%9 = tail call i32 (...) @getchar()
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = trunc i32 %9 to i8
%14 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %13, i8* %14
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %19, label %7
17: ; preds = %7
%18 = trunc i64 %8 to i32
br label %19
19: ; preds = %12, %17, %2
%20 = phi i32 [ 0, %2 ], [ %18, %17 ], [ %3, %12 ]
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 0, i8* %22
ret void
}