#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 */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, float, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *, float *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, float, char *);
int main() {
  FILE *arquivo;
  char nome[40], empresa[40];
  float fortuna;
  arquivo = fopen("dados.txt", "r+");
  if (arquivo == NULL)
    perror("Erro ao abrir dados.txt");
  else {
    int linha = 9;
    int atual = 0;
    int position = ftell(arquivo);
    while (fscanf(arquivo, "%s%f%s\n", nome, &fortuna, empresa) != EOF &&
           atual != linha) {
      position = ftell(arquivo);
      atual++;
    }
    fortuna = 47.5;
    fseek(arquivo, position + 1, SEEK_SET);
    fprintf(arquivo, "%s %.1f %s", nome, fortuna, empresa);
    printf("%s, com US$ %g bi (%s)\n", nome, fortuna, empresa);
    fclose(arquivo);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7c(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c5 <main+0x45>
lea    0xe4c(%rip),%rdi
call   10a0 <perror@plt>
jmp    12b6 <main+0x136>
movl   $0x9,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x80(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x70(%rbp),%r8
lea    0xe2d(%rip),%rsi
lea    -0x74(%rbp),%rcx
call   1050 <fscanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2de1(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x81(%rbp)
je     1225 <main+0xa5>
mov    -0x7c(%rbp),%eax
cmp    -0x78(%rbp),%eax
setne  %al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    1238 <main+0xb8>
jmp    1252 <main+0xd2>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x80(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    11df <main+0x5f>
movss  0xda6(%rip),%xmm0
movss  %xmm0,-0x74(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x80(%rbp),%esi
add    $0x1,%esi
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
movss  -0x74(%rbp),%xmm0
lea    -0x70(%rbp),%rcx
lea    0xd98(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x40(%rbp),%rsi
movss  -0x74(%rbp),%xmm0
lea    -0x70(%rbp),%rdx
lea    0xd8a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe7c(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ad <main+0x12d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
lea    0xe5d(%rip),%rsi
lea    0x40(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%rax
je     1239 <main+0xb9>
mov    $0x8,%r14d
lea    0x40(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
lea    0xe07(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1050 <fscanf@plt>
add    $0xffffffff,%r14d
setb   %cl
mov    0x2db8(%rip),%rdx
cmp    (%rdx),%rax
je     1239 <main+0xb9>
test   %cl,%cl
jne    1200 <main+0x80>
movl   $0x423e0000,0xc(%rsp)
42
add    $0x1,%ebp
mov    0x2d8d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <fseek@plt>
movss  0xc(%rsp),%xmm0
lea    0xdbf(%rip),%rsi
lea    0x40(%rsp),%rbp
lea    0x10(%rsp),%r14
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1060 <fprintf@plt>
movss  0xc(%rsp),%xmm0
lea    0xda5(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4f(%rip),%rdi
call   10a0 <perror@plt>
jmp    129c <main+0x11c>

LLVM IR (-O0):
@.str = [10 x i8] c"dados.txt\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [24 x i8] c"Erro ao abrir dados.txt\00"
@.str.3 = [8 x i8] c"%s%f%s\0A\00"
@EOF = global i64 0
@SEEK_SET = global i32 0
@.str.4 = [11 x i8] c"%s %.1f %s\00"
@.str.5 = [24 x i8] c"%s, com US$ %g bi (%s)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [40 x i8]
%4 = alloca [40 x i8]
%5 = alloca float
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %52
14: ; preds = %0
store i32 9, i32* %6
store i32 0, i32* %7
%15 = load i32*, i32** %2
%16 = call i32 @ftell(i32* %15)
store i32 %16, i32* %8
br label %17
17: ; preds = %30, %14
%18 = load i32*, i32** %2
%19 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%21 = call i64 @fscanf(i32* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %19, float* %5, i8* %20)
%22 = load i64, i64* @EOF
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i32, i32* %7
%26 = load i32, i32* %6
%27 = icmp ne i32 %25, %26
br label %28
28: ; preds = %24, %17
%29 = phi i1 [ false, %17 ], [ %27, %24 ]
br i1 %29, label %30, label %35
30: ; preds = %28
%31 = load i32*, i32** %2
%32 = call i32 @ftell(i32* %31)
store i32 %32, i32* %8
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %17
35: ; preds = %28
store float 4.750000e+01, float* %5
%36 = load i32*, i32** %2
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %36, i32 %38, i32 %39)
%41 = load i32*, i32** %2
%42 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%43 = load float, float* %5
%44 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%45 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %42, float %43, i8* %44)
%46 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%47 = load float, float* %5
%48 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %46, float %47, i8* %48)
%50 = load i32*, i32** %2
%51 = call i32 @fclose(i32* %50)
br label %52
52: ; preds = %35, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"dados.txt\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [24 x i8] c"Erro ao abrir dados.txt\00"
@.str.3 = [8 x i8] c"%s%f%s\0A\00"
@EOF = global i64 0
@SEEK_SET = global i32 0
@.str.4 = [11 x i8] c"%s %.1f %s\00"
@.str.5 = [24 x i8] c"%s, com US$ %g bi (%s)\0A\00"
define i32 @main() {
%1 = alloca [40 x i8]
%2 = alloca [40 x i8]
%3 = alloca float
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%6 = bitcast float* %3 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %35
11: ; preds = %0
%12 = tail call i32 @ftell(i32* %7)
%13 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %4, float* %3, i8* %5)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %25, label %16
16: ; preds = %11, %16
%17 = phi i32 [ %19, %16 ], [ 0, %11 ]
%18 = call i32 @ftell(i32* %7)
%19 = add nuw nsw i32 %17, 1
%20 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %4, float* %3, i8* %5)
%21 = load i64, i64* @EOF
%22 = icmp ne i64 %20, %21
%23 = icmp ne i32 %19, 9
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %16, label %25
25: ; preds = %16, %11
%26 = phi i32 [ %12, %11 ], [ %18, %16 ]
store float 4.750000e+01, float* %3
%27 = add nsw i32 %26, 1
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %7, i32 %27, i32 %28)
%30 = load float, float* %3
%31 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %4, float %30, i8* %5)
%32 = load float, float* %3
%33 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %4, float %32, i8* %5)
%34 = call i32 @fclose(i32* %7)
br label %35
35: ; preds = %25, %9
ret i32 0
}