#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 */
unsigned char fgetc(int /*<<< orphan*/ *);
void getData(unsigned char *str, FILE *fp, int max) {
  int i = 0;
  while ((*(str + i) = fgetc(fp)) && (i < (max - 2)))
    i++;
  str[i] = 0;
}


x86 assembly (clang, -O0):
<getData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
mov    %al,(%rcx,%rdx,1)
movzbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1160 <getData+0x50>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1170 <getData+0x60>
jmp    117e <getData+0x6e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <getData+0x1a>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getData>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
add    $0xfffffffe,%edx
movslq %edx,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %al,(%r15,%rbx,1)
lea    0x1(%rbx),%rcx
test   %al,%al
je     114c <getData+0x3c>
cmp    %r12,%rbx
mov    %rcx,%rbx
jl     1130 <getData+0x20>
movb   $0x0,-0x1(%r15,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @getData(i8* nocapture writeonly %0, i32* nocapture %1, i32 %2) {
%4 = add nsw i32 %2, -2
%5 = sext i32 %4 to i64
br label %6
6: ; preds = %6, %3
%7 = phi i64 [ %13, %6 ], [ 0, %3 ]
%8 = tail call zeroext i8 @fgetc(i32* %1)
%9 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 %8, i8* %9
%10 = icmp ne i8 %8, 0
%11 = icmp slt i64 %7, %5
%12 = select i1 %10, i1 %11, i1 false
%13 = add nuw nsw i64 %7, 1
br i1 %12, label %6, label %14
14: ; preds = %6
%15 = and i64 %7, 4294967295
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %16
ret void
}