#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
int main() {
  FILE *fp;
  FILE *lt;
  int resul;
  fp = fopen("SOMA.txt", "wt");
  lt = fopen("SOMA.txt", "rt");
  int a = 2;
  int b = 3;
  int c = a + b;
  int d = c;
  if (fp == NULL) {
    printf("Houve um erro ao abrir o arquivo.\n");
    return 1;
  }
  resul = fprintf(fp, "%d", c);
  if (resul == EOF) {
    printf("erro na gravaçã");
  }
  fscanf(lt, "%d", &d);
  printf("Arquivo soma criado com sucesso.\n ");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x20(%rbp)
movl   $0x3,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cd <main+0x7d>
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1231 <main+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe57(%rip),%rsi
call   1060 <fprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%eax
jne    1201 <main+0xb1>
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe26(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <fscanf@plt>
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%r14
lea    0xe97(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe88(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
movl   $0x5,0x4(%rsp)
test   %rbx,%rbx
je     11f3 <main+0x93>
mov    %rax,%r14
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1070 <fprintf@plt>
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%eax
jne    11c7 <main+0x67>
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
lea    0xe41(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1060 <fscanf@plt>
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1204 <main+0xa4>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"SOMA.txt\00"
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [3 x i8] c"rt\00"
@.str.3 = [35 x i8] c"Houve um erro ao abrir o arquivo.\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.5 = [18 x i8] c"erro na grava\C3\A7\C3\A3\00"
@.str.6 = [35 x i8] c"Arquivo soma criado com sucesso.\0A \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %3
store i32 2, i32* %5
store i32 3, i32* %6
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = add nsw i32 %11, %12
store i32 %13, i32* %7
%14 = load i32, i32* %7
store i32 %14, i32* %8
%15 = load i32*, i32** %2
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %34
19: ; preds = %0
%20 = load i32*, i32** %2
%21 = load i32, i32* %7
%22 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %28
28: ; preds = %26, %19
%29 = load i32*, i32** %3
%30 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %8)
%31 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
%32 = load i32*, i32** %2
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %1
br label %34
34: ; preds = %28, %17
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [9 x i8] c"SOMA.txt\00"
@.str.1 = [3 x i8] c"wt\00"
@.str.2 = [3 x i8] c"rt\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.5 = [18 x i8] c"erro na grava\C3\A7\C3\A3\00"
@.str.6 = [35 x i8] c"Arquivo soma criado com sucesso.\0A \00"
@str = [34 x i8] c"Houve um erro ao abrir o arquivo.\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
store i32 5, i32* %1
%5 = icmp eq i32* %2, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %18
8: ; preds = %0
%9 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 5)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
%17 = call i32 @fclose(i32* %2)
br label %18
18: ; preds = %14, %6
%19 = phi i32 [ 1, %6 ], [ 0, %14 ]
ret i32 %19
}