#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*/ free(char *);
char *readstring(int);
int /*<<< orphan*/ rtrim(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int readheader_topicfile(void) {
  char *s = readstring(1);
  if (s == NULL)
    do {
      fprintf(stderr, "Error: "
                      "Error in header. Aborting.");
      exit(1);
    } while (0);
  rtrim(s);
  fprintf(stderr, "### %s\n", s);
  free(s);
  s = readstring(1);
  if (s == NULL)
    do {
      fprintf(stderr, "Error: "
                      "Error in header. Aborting.");
      exit(1);
    } while (0);
  rtrim(s);
  fprintf(stderr, "### %s\n", s);
  if (strcmp(s, "Datei-Version 2.0") != 0) {
    fprintf(stderr, "WARNING: unknown version\n");
    free(s);
    return 0;
  } else {
    free(s);
    return 300;
  }
}


x86 assembly (clang, -O0):
<readheader_topicfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x1,%edi
call   1070 <readstring@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a7 <readheader_topicfile+0x47>
jmp    1186 <readheader_topicfile+0x26>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1050 <rtrim@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <readstring@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1213 <readheader_topicfile+0xb3>
jmp    11f2 <readheader_topicfile+0x92>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1050 <rtrim@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     127d <readheader_topicfile+0x11d>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    128d <readheader_topicfile+0x12d>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x12c,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readheader_topicfile>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%edi
call   1070 <readstring@plt>
test   %rax,%rax
je     1210 <readheader_topicfile+0xb0>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <rtrim@plt>
mov    0x2e57(%rip),%r14
mov    (%r14),%edi
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <readstring@plt>
test   %rax,%rax
je     121b <readheader_topicfile+0xbb>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <rtrim@plt>
mov    (%r14),%edi
lea    0xe59(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11fc <readheader_topicfile+0x9c>
mov    (%r14),%edi
lea    0xe49(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1201 <readheader_topicfile+0xa1>
mov    $0x12c,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
jmp    121e <readheader_topicfile+0xbe>
mov    (%r14),%edi
lea    0xddb(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Error: Error in header. Aborting.\00"
@.str.1 = [8 x i8] c"### %s\0A\00"
@.str.2 = [18 x i8] c"Datei-Version 2.0\00"
@.str.3 = [26 x i8] c"WARNING: unknown version\0A\00"
define i32 @readheader_topicfile() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i8* @readstring(i32 1)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %12
6: ; preds = %0
br label %7
7: ; preds = %6
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; No predecessors!
br label %12
12: ; preds = %11, %0
%13 = load i8*, i8** %2
%14 = call i32 @rtrim(i8* %13)
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %2
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %2
%19 = call i32 @free(i8* %18)
%20 = call i8* @readstring(i32 1)
store i8* %20, i8** %2
%21 = load i8*, i8** %2
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %29
23: ; preds = %12
br label %24
24: ; preds = %23
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; No predecessors!
br label %29
29: ; preds = %28, %12
%30 = load i8*, i8** %2
%31 = call i32 @rtrim(i8* %30)
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %2
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %2
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %29
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%41 = load i8*, i8** %2
%42 = call i32 @free(i8* %41)
store i32 0, i32* %1
br label %46
43: ; preds = %29
%44 = load i8*, i8** %2
%45 = call i32 @free(i8* %44)
store i32 300, i32* %1
br label %46
46: ; preds = %43, %38
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Error: Error in header. Aborting.\00"
@.str.1 = [8 x i8] c"### %s\0A\00"
@.str.2 = [18 x i8] c"Datei-Version 2.0\00"
@.str.3 = [26 x i8] c"WARNING: unknown version\0A\00"
define i32 @readheader_topicfile() {
%1 = tail call i8* @readstring(i32 1)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 @rtrim(i8* %1)
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%11 = tail call i32 @free(i8* %1)
%12 = tail call i8* @readstring(i32 1)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %7
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %7
%19 = tail call i32 @rtrim(i8* %12)
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%22 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %18, %24
%28 = phi i32 [ 0, %24 ], [ 300, %18 ]
%29 = tail call i32 @free(i8* %12)
ret i32 %28
}