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


x86 assembly (clang, -O0):
<ex2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xea1(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x32,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11d8 <ex2+0x88>
movsbl -0x50(%rbp),%eax
cmp    $0x23,%eax
je     11d3 <ex2+0x83>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
jmp    1186 <ex2+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):
<ex2>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe95(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x32,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e3 <ex2+0x93>
mov    %rsp,%rbx
lea    0xe76(%rip),%r12
jmp    11c5 <ex2+0x75>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e3 <ex2+0x93>
cmpb   $0x23,(%rsp)
je     11b0 <ex2+0x60>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    11b0 <ex2+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
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"%s\00"
define void @ex2() {
%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 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 35
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i32*, i32** %2
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %16, %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"%s\00"
define void @ex2() {
%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 = load i8, i8* %4
%9 = icmp eq i8 %8, 35
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i32 @fputs(i8* %4, i32* %3)
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %13
13: ; preds = %10, %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
}