#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 */
char EOF;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
char *safeGetString(char *str, int buffSize) {
  char *pos;
  if (!fgets(str, buffSize, stdin))
    return NULL;
  if ((pos = strchr(str, '\n')))
    *pos = '\0';
  else {
    char temp;
    while ((temp = getchar()) != '\n' && temp != EOF)
      ;
  }
  return str;
}


x86 assembly (clang, -O0):
<safeGetString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    116a <safeGetString+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    11ea <safeGetString+0xba>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1192 <safeGetString+0x62>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    11e2 <safeGetString+0xb2>
jmp    1197 <safeGetString+0x67>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x22(%rbp)
je     11c8 <safeGetString+0x98>
movsbl -0x21(%rbp),%eax
mov    0x2e23(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11d8 <safeGetString+0xa8>
jmp    11dd <safeGetString+0xad>
jmp    1197 <safeGetString+0x67>
jmp    11e2 <safeGetString+0xb2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safeGetString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eaa(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
test   %eax,%eax
je     1160 <safeGetString+0x30>
mov    %r14,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1165 <safeGetString+0x35>
movb   $0x0,(%rax)
jmp    117f <safeGetString+0x4f>
xor    %r14d,%r14d
jmp    117f <safeGetString+0x4f>
mov    0x2e74(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     117f <safeGetString+0x4f>
cmp    (%rbx),%al
jne    1170 <safeGetString+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i8 0
define i8* @safeGetString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %8, i32 %9, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %2
store i8* null, i8** %3
br label %37
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i8* @strchr(i8* %15, i8 signext 10)
store i8* %16, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i8*, i8** %6
store i8 0, i8* %19
br label %35
20: ; preds = %14
br label %21
21: ; preds = %33, %20
%22 = call signext i8 (...) @getchar()
store i8 %22, i8* %7
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 10
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8, i8* %7
%27 = sext i8 %26 to i32
%28 = load i8, i8* @EOF
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %27, %29
br label %31
31: ; preds = %25, %21
%32 = phi i1 [ false, %21 ], [ %30, %25 ]
br i1 %32, label %33, label %34
33: ; preds = %31
br label %21
34: ; preds = %31
br label %35
35: ; preds = %34, %18
%36 = load i8*, i8** %4
store i8* %36, i8** %3
br label %37
37: ; preds = %35, %13
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i8 0
define i8* @safeGetString(i8* %0, i32 %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %0, i32 %1, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %6
store i8 0, i8* %7
br label %16
10: ; preds = %6, %10
%11 = tail call signext i8 (...) @getchar()
%12 = icmp ne i8 %11, 10
%13 = load i8, i8* @EOF
%14 = icmp ne i8 %11, %13
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %10, label %16
16: ; preds = %10, %9, %2
%17 = phi i8* [ null, %2 ], [ %0, %9 ], [ %0, %10 ]
ret i8* %17
}