#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 fgetc(int /*<<< orphan*/ *);
int FReadString(FILE *fp, char *str, int n) {
  int x = 0, z;
  for (;;) {
    z = fgetc(fp);
    str[x] = z;
    x++;
    if (z <= 0)
      break;
    if (x >= n)
      return 0;
  }
  if (z < 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<FReadString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
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)
cmpl   $0x0,-0x24(%rbp)
jg     115e <FReadString+0x4e>
jmp    117b <FReadString+0x6b>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1176 <FReadString+0x66>
movl   $0x0,-0x4(%rbp)
jmp    1198 <FReadString+0x88>
jmp    112a <FReadString+0x1a>
cmpl   $0x0,-0x24(%rbp)
jge    1191 <FReadString+0x81>
movl   $0x0,-0x4(%rbp)
jmp    1198 <FReadString+0x88>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FReadString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0x2,%edx
mov    $0x1,%r12d
cmovge %edx,%r12d
xor    %ebx,%ebx
nopl   (%rax)
mov    %r15,%rdi
call   1030 <fgetc@plt>
mov    %al,(%r14,%rbx,1)
test   %eax,%eax
jle    114d <FReadString+0x3d>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <FReadString+0x20>
xor    %eax,%eax
jmp    1153 <FReadString+0x43>
sete   %al
movzbl %al,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @FReadString(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
store i32 0, i32* %8
br label %10
10: ; preds = %29, %3
%11 = load i32*, i32** %5
%12 = call i32 @fgetc(i32* %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %6
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 %14, i8* %18
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
store i32 %20, i32* %8
%21 = load i32, i32* %9
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %10
br label %30
24: ; preds = %10
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = icmp sge i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 0, i32* %4
br label %35
29: ; preds = %24
br label %10
30: ; preds = %23
%31 = load i32, i32* %9
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 0, i32* %4
br label %35
34: ; preds = %30
store i32 1, i32* %4
br label %35
35: ; preds = %34, %33, %28
%36 = load i32, i32* %4
ret i32 %36
}

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