#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 */
char *calloc(int, int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ handle_command(char *);
char *strchr(char *, char);
void source_fp(const FILE *fp) {
  char *line;
  line = calloc(1024, sizeof(char));
  while (fgets(line, 1024, (FILE *)fp)) {
    char *val;
    if (line[0] == '#' || line[0] == '\n') {
      continue;
    }
    if ((val = strchr(line, '#'))) {
      *val = '\0';
    } else {
      handle_command(line);
    }
    free(line);
    line = calloc(1024, sizeof(char));
  }
  free(line);
}


x86 assembly (clang, -O0):
<source_fp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x400,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1202 <source_fp+0xb2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     11ab <source_fp+0x5b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11b0 <source_fp+0x60>
jmp    116f <source_fp+0x1f>
mov    -0x10(%rbp),%rdi
mov    $0x23,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d8 <source_fp+0x88>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11e1 <source_fp+0x91>
mov    -0x10(%rbp),%rdi
call   1040 <handle_command@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x400,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x10(%rbp)
jmp    116f <source_fp+0x1f>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<source_fp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x400,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
jmp    1193 <source_fp+0x43>
mov    %rbx,%rdi
call   1040 <handle_command@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x400,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11c7 <source_fp+0x77>
movzbl (%rbx),%eax
cmp    $0xa,%al
je     1190 <source_fp+0x40>
cmp    $0x23,%al
je     1190 <source_fp+0x40>
mov    %rbx,%rdi
mov    $0x23,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     116e <source_fp+0x1e>
movb   $0x0,(%rax)
jmp    1176 <source_fp+0x26>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @source_fp(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
store i32* %0, i32** %2
%5 = call i8* @calloc(i32 1024, i32 1)
store i8* %5, i8** %3
br label %6
6: ; preds = %33, %23, %1
%7 = load i8*, i8** %3
%8 = load i32*, i32** %2
%9 = call i64 @fgets(i8* %7, i32 1024, i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %37
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 35
br i1 %16, label %23, label %17
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %17, %11
br label %6
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = call i8* @strchr(i8* %25, i8 signext 35)
store i8* %26, i8** %4
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i8*, i8** %4
store i8 0, i8* %29
br label %33
30: ; preds = %24
%31 = load i8*, i8** %3
%32 = call i32 @handle_command(i8* %31)
br label %33
33: ; preds = %30, %28
%34 = load i8*, i8** %3
%35 = call i32 @free(i8* %34)
%36 = call i8* @calloc(i32 1024, i32 1)
store i8* %36, i8** %3
br label %6
37: ; preds = %6
%38 = load i8*, i8** %3
%39 = call i32 @free(i8* %38)
ret void
}

LLVM IR (-O2):
define void @source_fp(i32* nocapture %0) {
%2 = tail call dereferenceable_or_null(1024) i8* @calloc(i32 1024, i32 1)
%3 = tail call i64 @fgets(i8* %2, i32 1024, i32* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %21, label %5
5: ; preds = %1, %17
%6 = phi i8* [ %18, %17 ], [ %2, %1 ]
%7 = load i8, i8* %6
switch i8 %7, label %8 [
i8 35, label %17
i8 10, label %17
]
8: ; preds = %5
%9 = tail call i8* @strchr(i8* %6, i8 signext 35)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %8
store i8 0, i8* %9
br label %14
12: ; preds = %8
%13 = tail call i32 @handle_command(i8* %6)
br label %14
14: ; preds = %12, %11
%15 = tail call i32 @free(i8* %6)
%16 = tail call dereferenceable_or_null(1024) i8* @calloc(i32 1024, i32 1)
br label %17
17: ; preds = %5, %5, %14
%18 = phi i8* [ %16, %14 ], [ %6, %5 ], [ %6, %5 ]
%19 = tail call i64 @fgets(i8* %18, i32 1024, i32* %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %5
21: ; preds = %17, %1
%22 = phi i8* [ %2, %1 ], [ %18, %17 ]
%23 = tail call i32 @free(i8* %22)
ret void
}