#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 */
long fgets(char *, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
char *realloc(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncat(char *, char *, int);
void insult(long rand, FILE *insults) {
  char zeichen[2];
  long anzahl = 0;
  long stop = 1;
  do {
    int i = 0;
    int durchlauf = 0;
    char *line = malloc(2 * sizeof(char));
    char *newline;
    stop = fgets(zeichen, 2, insults);
    i = (zeichen[0] == '\n') ? 0 : 1;
    strcpy(line, zeichen);
    do {
      stop = fgets(zeichen, 2, insults);
      i = (zeichen[0] == '\n') ? 0 : 1;
      newline = realloc(line, (durchlauf * 2 + 3) * sizeof(char));
      line = newline;
      strncat(line, zeichen, 1);
      durchlauf++;
    } while (i == 1 && stop);
    anzahl++;
    if (anzahl == rand) {
      stop = 0;
      printf("%s", line);
    }
  } while (stop);
}


x86 assembly (clang, -O0):
<insult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
lea    -0x12(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2,%esi
call   1060 <fgets@plt>
mov    %rax,-0x28(%rbp)
movsbl -0x12(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0xa,%edx
cmove  %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x12(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x12(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2,%esi
call   1060 <fgets@plt>
mov    %rax,-0x28(%rbp)
movsbl -0x12(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0xa,%edx
cmove  %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%eax
shl    $0x1,%eax
add    $0x3,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x12(%rbp),%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x2c(%rbp)
mov    %al,-0x41(%rbp)
jne    1258 <insult+0xf8>
cmpq   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11d3 <insult+0x73>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1295 <insult+0x135>
movq   $0x0,-0x28(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xd70(%rip),%rdi
call   1040 <printf@plt>
jmp    129a <insult+0x13a>
cmpq   $0x0,-0x28(%rbp)
jne    1180 <insult+0x20>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insult>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,0x8(%rsp)
xor    %eax,%eax
lea    0x6(%rsp),%r12
nopl   (%rax)
mov    %rax,0x10(%rsp)
mov    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
mov    %rax,%rbx
movzbl 0x6(%rsp),%r14d
mov    %r13,%rdi
mov    %ebp,%esi
call   1080 <realloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
test   %rbx,%rbx
je     1204 <insult+0xa4>
add    $0x2,%ebp
cmp    $0xa,%r14b
jne    11c0 <insult+0x60>
mov    0x10(%rsp),%rax
add    $0x1,%rax
cmp    0x8(%rsp),%rax
je     121f <insult+0xbf>
test   %rbx,%rbx
jne    1180 <insult+0x20>
jmp    122e <insult+0xce>
lea    0xdda(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @insult(i64 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca [2 x i8]
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i64 %0, i64* %3
store i32* %1, i32** %4
store i64 0, i64* %6
store i64 1, i64* %7
br label %12
12: ; preds = %68, %2
store i32 0, i32* %8
store i32 0, i32* %9
%13 = call i8* @malloc(i32 2)
store i8* %13, i8** %10
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i64 @fgets(i8* %14, i32 2, i32* %15)
store i64 %16, i64* %7
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 0, i32 1
store i32 %22, i32* %8
%23 = load i8*, i8** %10
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%25 = call i32 @strcpy(i8* %23, i8* %24)
br label %26
26: ; preds = %56, %12
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%28 = load i32*, i32** %4
%29 = call i64 @fgets(i8* %27, i32 2, i32* %28)
store i64 %29, i64* %7
%30 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 10
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 0, i32 1
store i32 %35, i32* %8
%36 = load i8*, i8** %10
%37 = load i32, i32* %9
%38 = mul nsw i32 %37, 2
%39 = add nsw i32 %38, 3
%40 = sext i32 %39 to i64
%41 = mul i64 %40, 1
%42 = trunc i64 %41 to i32
%43 = call i8* @realloc(i8* %36, i32 %42)
store i8* %43, i8** %11
%44 = load i8*, i8** %11
store i8* %44, i8** %10
%45 = load i8*, i8** %10
%46 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%47 = call i32 @strncat(i8* %45, i8* %46, i32 1)
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %50
50: ; preds = %26
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i64, i64* %7
%55 = icmp ne i64 %54, 0
br label %56
56: ; preds = %53, %50
%57 = phi i1 [ false, %50 ], [ %55, %53 ]
br i1 %57, label %26, label %58
58: ; preds = %56
%59 = load i64, i64* %6
%60 = add nsw i64 %59, 1
store i64 %60, i64* %6
%61 = load i64, i64* %6
%62 = load i64, i64* %3
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %67
64: ; preds = %58
store i64 0, i64* %7
%65 = load i8*, i8** %10
%66 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %64, %58
br label %68
68: ; preds = %67
%69 = load i64, i64* %7
%70 = icmp ne i64 %69, 0
br i1 %70, label %12, label %71
71: ; preds = %68
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define void @insult(i64 %0, i32* nocapture %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %28, %2
%6 = phi i64 [ 0, %2 ], [ %24, %28 ]
%7 = call dereferenceable_or_null(2) i8* @malloc(i32 2)
%8 = call i64 @fgets(i8* %4, i32 2, i32* %1)
%9 = call i32 @strcpy(i8* %7, i8* %4)
br label %10
10: ; preds = %10, %5
%11 = phi i32 [ 0, %5 ], [ %20, %10 ]
%12 = phi i8* [ %7, %5 ], [ %18, %10 ]
%13 = call i64 @fgets(i8* %4, i32 2, i32* %1)
%14 = load i8, i8* %4
%15 = icmp ne i8 %14, 10
%16 = shl nuw nsw i32 %11, 1
%17 = add nuw nsw i32 %16, 3
%18 = call i8* @realloc(i8* %12, i32 %17)
%19 = call i32 @strncat(i8* %18, i8* %4, i32 1)
%20 = add nuw nsw i32 %11, 1
%21 = icmp ne i64 %13, 0
%22 = and i1 %21, %15
br i1 %22, label %10, label %23
23: ; preds = %10
%24 = add nuw nsw i64 %6, 1
%25 = icmp eq i64 %24, %0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %30
28: ; preds = %23
%29 = icmp eq i64 %13, 0
br i1 %29, label %30, label %5
30: ; preds = %28, %26
ret void
}