#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strdup(char *);
char *strndup(char *, int);
char *newlineCut(char *str) {
  char *newline = strchr(str, '\n');
  char *newstr = (newline == NULL) ? strdup(str) : strndup(str, newline - str);
  if (newstr == NULL) {
    fprintf(stderr, "Speicherallokationsfehler\n");
    exit(1);
  }
  return newstr;
}


x86 assembly (clang, -O0):
<newlineCut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118b <newlineCut+0x3b>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    11a5 <newlineCut+0x55>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1040 <strndup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d7 <newlineCut+0x87>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newlineCut>:
push   %rbx
mov    %rdi,%rbx
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1176 <newlineCut+0x26>
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <strndup@plt>
test   %rax,%rax
je     1183 <newlineCut+0x33>
pop    %rbx
ret
mov    %rbx,%rdi
call   1070 <strdup@plt>
test   %rax,%rax
jne    1174 <newlineCut+0x24>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Speicherallokationsfehler\0A\00"
define i8* @newlineCut(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 10)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i8* @strdup(i8* %10)
br label %21
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = load i8*, i8** %3
%15 = load i8*, i8** %2
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @strndup(i8* %13, i32 %19)
br label %21
21: ; preds = %12, %9
%22 = phi i8* [ %11, %9 ], [ %20, %12 ]
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i8*, i8** %4
ret i8* %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Speicherallokationsfehler\0A\00"
define i8* @newlineCut(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
br label %12
6: ; preds = %1
%7 = ptrtoint i8* %2 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = tail call i8* @strndup(i8* %0, i32 %10)
br label %12
12: ; preds = %6, %4
%13 = phi i8* [ %5, %4 ], [ %11, %6 ]
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %12
ret i8* %13
}