#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int ReadChars(FILE *fptr, char *s, int n) {
  int i, c;
  if (sizeof(char) != 1) {
    fprintf(stderr, "ReadChars: sizeof(char)=%ld and not 1\n", sizeof(char));
    exit(0);
  }
  s[0] = '\0';
  for (i = 0; i < n; i++) {
    c = fgetc(fptr);
    if (c == EOF)
      return (0);
    s[i] = c;
  }
  return (1);
}


x86 assembly (clang, -O0):
<ReadChars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1185 <ReadChars+0x75>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e95(%rip),%rcx
cmp    (%rcx),%eax
jne    1167 <ReadChars+0x57>
movl   $0x0,-0x4(%rbp)
jmp    118c <ReadChars+0x7c>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1131 <ReadChars+0x21>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadChars>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,(%rsi)
mov    $0x1,%r14d
test   %edx,%edx
jle    115f <ReadChars+0x4f>
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebp,%ebp
mov    0x2eae(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     115c <ReadChars+0x4c>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1140 <ReadChars+0x30>
jmp    115f <ReadChars+0x4f>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
define i32 @ReadChars(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
store i8 0, i8* %1
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %12
%8 = phi i64 [ 0, %5 ], [ %15, %12 ]
%9 = tail call i32 @fgetc(i32* %0)
%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* %1, i64 %8
store i8 %13, i8* %14
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %17, label %7
17: ; preds = %7, %12, %3
%18 = phi i32 [ 1, %3 ], [ 1, %12 ], [ 0, %7 ]
ret i32 %18
}