#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
void ex4(char *in, char *out) {
  FILE *teste, *new;
  teste = fopen(in, "r");
  new = fopen(out, "w+");
  char *buffer = malloc(1024 * sizeof(char));
  while (fgets(buffer, 1024, teste) != NULL)
    fprintf(new, buffer);
  while (strcmp(buffer, "exit") != 0) {
    printf("Digite o RA: ");
    fgets(buffer, 1024, stdin);
    fprintf(new, buffer);
    printf("Digite o NOME: ");
    fgets(buffer, 1024, stdin);
    fprintf(new, buffer);
  }
}


x86 assembly (clang, -O0):
<ex4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11d4 <ex4+0x74>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <fprintf@plt>
jmp    11a6 <ex4+0x46>
jmp    11d9 <ex4+0x79>
mov    -0x28(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     125a <ex4+0xfa>
lea    0xe10(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2dde(%rip),%rax
mov    (%rax),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <fprintf@plt>
lea    0xded(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2dad(%rip),%rax
mov    (%rax),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <fprintf@plt>
jmp    11d9 <ex4+0x79>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xe8b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
nop
mov    $0x400,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c2 <ex4+0x62>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
jmp    11a0 <ex4+0x40>
lea    0xe3c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1258 <ex4+0xf8>
lea    0xe29(%rip),%r15
mov    0x2e00(%rip),%rbp
lea    0xe29(%rip),%r12
lea    0xe0f(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <printf@plt>
mov    0x0(%rbp),%rdx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <fprintf@plt>
mov    %r12,%rdi
call   1030 <printf@plt>
mov    0x0(%rbp),%rdx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1200 <ex4+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [14 x i8] c"Digite o RA: \00"
@stdin = global i32* null
@.str.4 = [16 x i8] c"Digite o NOME: \00"
define void @ex4(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = call i8* @malloc(i32 1024)
store i8* %12, i8** %7
br label %13
13: ; preds = %18, %2
%14 = load i8*, i8** %7
%15 = load i32*, i32** %5
%16 = call i32* @fgets(i8* %14, i32 1024, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32*, i32** %6
%20 = load i8*, i8** %7
%21 = call i32 @fprintf(i32* %19, i8* %20)
br label %13
22: ; preds = %13
br label %23
23: ; preds = %27, %22
%24 = load i8*, i8** %7
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %23
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%29 = load i8*, i8** %7
%30 = load i32*, i32** @stdin
%31 = call i32* @fgets(i8* %29, i32 1024, i32* %30)
%32 = load i32*, i32** %6
%33 = load i8*, i8** %7
%34 = call i32 @fprintf(i32* %32, i8* %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%36 = load i8*, i8** %7
%37 = load i32*, i32** @stdin
%38 = call i32* @fgets(i8* %36, i32 1024, i32* %37)
%39 = load i32*, i32** %6
%40 = load i8*, i8** %7
%41 = call i32 @fprintf(i32* %39, i8* %40)
br label %23
42: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [14 x i8] c"Digite o RA: \00"
@stdin = global i32* null
@.str.4 = [16 x i8] c"Digite o NOME: \00"
define void @ex4(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = tail call i32* @fgets(i8* %5, i32 1024, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %11, %2
%9 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %26, label %15
11: ; preds = %2, %11
%12 = tail call i32 @fprintf(i32* %4, i8* %5)
%13 = tail call i32* @fgets(i8* %5, i32 1024, i32* %3)
%14 = icmp eq i32* %13, null
br i1 %14, label %8, label %11
15: ; preds = %8, %15
%16 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32*, i32** @stdin
%18 = tail call i32* @fgets(i8* %5, i32 1024, i32* %17)
%19 = tail call i32 @fprintf(i32* %4, i8* %5)
%20 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%21 = load i32*, i32** @stdin
%22 = tail call i32* @fgets(i8* %5, i32 1024, i32* %21)
%23 = tail call i32 @fprintf(i32* %4, i8* %5)
%24 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %15
26: ; preds = %15, %8
ret void
}