#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 /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
char *strchr(char *, char);
scalar_t__ strlen(char *);
void fgets2(char *s, int n, FILE *stream) {
  char *TEMP;
  (void)fgets(s, n, stream);
  TEMP = strchr(s, '\n');
  if (TEMP != NULL)
    *TEMP = 0;
  if ((int)strlen(s) > n - 2) {
    printf("INFO:  auxfunc.c - fgets2 -- BUFFER OVERFLOW, maximum string size "
           "of %d characters exceeded. Increase LONGSTRINGSIZE in auxfunc.h\n",
           4096);
  }
}


x86 assembly (clang, -O0):
<fgets2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <fgets@plt>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1187 <fgets2+0x47>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jle    11af <fgets2+0x6f>
lea    0xe5b(%rip),%rdi
mov    $0x1000,%esi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgets2>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
call   1060 <fgets@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1163 <fgets2+0x23>
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0xfffffffe,%ebx
cmp    %eax,%ebx
jge    118a <fgets2+0x4a>
lea    0xe87(%rip),%rdi
mov    $0x1000,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [131 x i8] c"INFO: auxfunc.c - fgets2 -- BUFFER OVERFLOW, maximum string size of %d characters exceeded. Increase LONGSTRINGSIZE in auxfunc.h\0A\00"
define void @fgets2(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = load i32*, i32** %6
%11 = call i32 @fgets(i8* %8, i32 %9, i32* %10)
%12 = load i8*, i8** %4
%13 = call i8* @strchr(i8* %12, i8 signext 10)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i8*, i8** %7
store i8 0, i8* %17
br label %18
18: ; preds = %16, %3
%19 = load i8*, i8** %4
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 2
%24 = icmp sgt i32 %21, %23
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str, i64 0, i64 0), i32 4096)
br label %27
27: ; preds = %25, %18
ret void
}

LLVM IR (-O2):
@.str = [131 x i8] c"INFO: auxfunc.c - fgets2 -- BUFFER OVERFLOW, maximum string size of %d characters exceeded. Increase LONGSTRINGSIZE in auxfunc.h\0A\00"
define void @fgets2(i8* %0, i32 %1, i32* nocapture %2) {
%4 = tail call i32 @fgets(i8* %0, i32 %1, i32* %2)
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%6 = icmp eq i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %3
store i8 0, i8* %5
br label %8
8: ; preds = %7, %3
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = trunc i64 %9 to i32
%11 = add nsw i32 %1, -2
%12 = icmp slt i32 %11, %10
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @printf(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str, i64 0, i64 0), i32 4096)
br label %15
15: ; preds = %13, %8
ret void
}