#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ strtok(char *, char *);
void ex3() {
  FILE *linhas, *linhas2;
  linhas = fopen("linhas.txt", "r");
  linhas2 = fopen("linhas2.txt", "w+");
  char linha[50];
  while (fgets(linha, 50, linhas) != NULL) {
    strtok(linha, "#\n");
    if (linha[0] != '#')
      fprintf(linhas2, "%s\n", linha);
  }
  fclose(linhas);
  fclose(linhas2);
}


x86 assembly (clang, -O0):
<ex3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xea1(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x32,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11d8 <ex3+0x88>
lea    -0x50(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <strtok@plt>
movsbl -0x50(%rbp),%eax
cmp    $0x23,%eax
je     11d3 <ex3+0x83>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe51(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1186 <ex3+0x36>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex3>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
lea    0xe9c(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
lea    0xe93(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x32,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f6 <ex3+0xa6>
lea    0xe77(%rip),%r15
mov    %rsp,%rbx
lea    0xe70(%rip),%r13
jmp    11d5 <ex3+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f6 <ex3+0xa6>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strtok@plt>
cmpb   $0x23,(%rsp)
je     11c0 <ex3+0x70>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
jmp    11c0 <ex3+0x70>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"linhas.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"linhas2.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [3 x i8] c"#\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define void @ex3() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca [50 x i8]
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %5, i32** %2
br label %6
6: ; preds = %22, %0
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%8 = load i32*, i32** %1
%9 = call i32* @fgets(i8* %7, i32 50, i32* %8)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %23
11: ; preds = %6
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%13 = call i32 @strtok(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 35
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i32*, i32** %2
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%21 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18, %11
br label %6
23: ; preds = %6
%24 = load i32*, i32** %1
%25 = call i32 @fclose(i32* %24)
%26 = load i32*, i32** %2
%27 = call i32 @fclose(i32* %26)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"linhas.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"linhas2.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [3 x i8] c"#\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define void @ex3() {
%1 = alloca [50 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%5 = call i32* @fgets(i8* %4, i32 50, i32* %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %16, label %7
7: ; preds = %0, %13
%8 = call i32 @strtok(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%9 = load i8, i8* %4
%10 = icmp eq i8 %9, 35
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %13
13: ; preds = %11, %7
%14 = call i32* @fgets(i8* %4, i32 50, i32* %2)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %7
16: ; preds = %13, %0
%17 = call i32 @fclose(i32* %2)
%18 = call i32 @fclose(i32* %3)
ret void
}