#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, char *, double);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  FILE *fp;
  char titulo[40];
  int codigo;
  double preco;
  if ((fp = fopen("arqtext.txt", "w")) == NULL) {
    printf("\nO arquivo não pode ser aberto");
    exit(1);
  } else {
    printf("\nO arquivo foi aberto para gravação");
  }
  while (1) {
    printf("\nDigite o código do livro ou -1 para sair: ");
    scanf("%d", &codigo);
    if (codigo == -1)
      break;
    printf("\nDigite o título do livro:");
    scanf("%s", titulo);
    printf("\nDigite o preço do livro:");
    scanf("%lf", &preco);
    fprintf(fp, "%d %s %lf \n", codigo, titulo, preco);
  }
  fclose(fp);
  printf("\nFim do programa!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a6 <main+0x46>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
jmp    11b7 <main+0x57>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x44(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0xffffffff,-0x44(%rbp)
jne    11e4 <main+0x84>
jmp    1241 <main+0xe1>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xea9(%rip),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x44(%rbp),%edx
lea    -0x40(%rbp),%rcx
movsd  -0x50(%rbp),%xmm0
lea    0xe8b(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11b7 <main+0x57>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1285 <main+0x125>
mov    %rax,%r12
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
lea    0xed5(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0xffffffff,0x4(%rsp)
je     1260 <main+0x100>
lea    0x10(%rsp),%rbx
lea    0xef3(%rip),%r15
lea    0xe7e(%rip),%r13
lea    0xea4(%rip),%rbp
lea    0x4(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%edx
movsd  0x8(%rsp),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rcx
call   1050 <fprintf@plt>
mov    %r13,%rdi
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0xffffffff,0x4(%rsp)
jne    11f0 <main+0x90>
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd82(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"arqtext.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [32 x i8] c"\0AO arquivo n\C3\A3o pode ser aberto\00"
@.str.3 = [38 x i8] c"\0AO arquivo foi aberto para grava\C3\A7\C3\A3o\00"
@.str.4 = [45 x i8] c"\0ADigite o c\C3\B3digo do livro ou -1 para sair: \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [28 x i8] c"\0ADigite o t\C3\ADtulo do livro:\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [27 x i8] c"\0ADigite o pre\C3\A7o do livro:\00"
@.str.9 = [4 x i8] c"%lf\00"
@.str.10 = [12 x i8] c"%d %s %lf \0A\00"
@.str.11 = [18 x i8] c"\0AFim do programa!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [40 x i8]
%4 = alloca i32
%5 = alloca double
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11
br label %14
14: ; preds = %13, %20
%15 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %4)
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %14
br label %31
20: ; preds = %14
%21 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%22 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), double* %5)
%26 = load i32*, i32** %2
%27 = load i32, i32* %4
%28 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%29 = load double, double* %5
%30 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %27, i8* %28, double %29)
br label %14
31: ; preds = %19
%32 = load i32*, i32** %2
%33 = call i32 @fclose(i32* %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"arqtext.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [32 x i8] c"\0AO arquivo n\C3\A3o pode ser aberto\00"
@.str.3 = [38 x i8] c"\0AO arquivo foi aberto para grava\C3\A7\C3\A3o\00"
@.str.4 = [45 x i8] c"\0ADigite o c\C3\B3digo do livro ou -1 para sair: \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [28 x i8] c"\0ADigite o t\C3\ADtulo do livro:\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [27 x i8] c"\0ADigite o pre\C3\A7o do livro:\00"
@.str.9 = [4 x i8] c"%lf\00"
@.str.10 = [12 x i8] c"%d %s %lf \0A\00"
@.str.11 = [18 x i8] c"\0AFim do programa!\00"
define i32 @main() {
%1 = alloca [40 x i8]
%2 = alloca i32
%3 = alloca double
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, -1
br i1 %17, label %30, label %18
18: ; preds = %12, %18
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), double* %3)
%23 = load i32, i32* %2
%24 = load double, double* %3
%25 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 %23, i8* %4, double %24)
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%28 = load i32, i32* %2
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %18
30: ; preds = %18, %12
%31 = call i32 @fclose(i32* %7)
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}