#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  int a, b, menor, maior, menors = 0;
  char nomearquivo[30];
  FILE *arq;
  printf("Digite o nome do arquivo: \n");
  scanf("%s", nomearquivo);
  arq = fopen(nomearquivo, "r");
  while ((fscanf(arq, "%i %i", &a, &b)) != EOF) {
    printf("%d %d\n", a, b);
    if (a >= b) {
      maior = a;
      printf("Maior = %i\n", a);
      menor = b;
    } else {
      maior = b;
      printf("Maior = %i\n", b);
      menor = a;
    }
    menors = menors + menor;
  }
  printf("A soma dos menores = %i\n", menors);
  fclose(arq);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe9d(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xe7e(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   1050 <fscanf@plt>
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
je     122d <main+0xdd>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1202 <main+0xb2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    121f <main+0xcf>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <main+0x48>
mov    -0x18(%rbp),%esi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@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    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe5e(%rip),%rsi
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r13
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r13,%rcx
call   1060 <fscanf@plt>
mov    0x2e22(%rip),%r12
xor    %ebp,%ebp
cmp    (%r12),%rax
je     1225 <main+0xc5>
xor    %ebp,%ebp
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%eax
cmp    %eax,%esi
cmovl  %eax,%esi
mov    %r13,%rbx
cmovl  %r15,%rbx
lea    0xe11(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    (%rbx),%ebp
mov    %r14,%rdi
lea    0xdf1(%rip),%rsi
mov    %r15,%rdx
mov    %r13,%rcx
call   1060 <fscanf@plt>
cmp    (%r12),%rax
jne    11d0 <main+0x70>
lea    0xdf2(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Digite o nome do arquivo: \0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%i %i\00"
@EOF = global i64 0
@.str.4 = [7 x i8] c"%d %d\0A\00"
@.str.5 = [12 x i8] c"Maior = %i\0A\00"
@.str.6 = [25 x i8] c"A soma dos menores = %i\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 [30 x i8]
%8 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %8
br label %14
14: ; preds = %36, %0
%15 = load i32*, i32** %8
%16 = call i64 @fscanf(i32* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32* %3)
%17 = load i64, i64* @EOF
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %40
19: ; preds = %14
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = icmp sge i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i32, i32* %2
store i32 %27, i32* %5
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %3
store i32 %30, i32* %4
br label %36
31: ; preds = %19
%32 = load i32, i32* %3
store i32 %32, i32* %5
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %2
store i32 %35, i32* %4
br label %36
36: ; preds = %31, %26
%37 = load i32, i32* %6
%38 = load i32, i32* %4
%39 = add nsw i32 %37, %38
store i32 %39, i32* %6
br label %14
40: ; preds = %14
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%43 = load i32*, i32** %8
%44 = call i32 @fclose(i32* %43)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%i %i\00"
@EOF = global i64 0
@.str.4 = [7 x i8] c"%d %d\0A\00"
@.str.5 = [12 x i8] c"Maior = %i\0A\00"
@.str.6 = [25 x i8] c"A soma dos menores = %i\0A\00"
@str = [27 x i8] c"Digite o nome do arquivo: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [30 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%9 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
br i1 %12, label %30, label %13
13: ; preds = %0, %13
%14 = phi i32 [ %26, %13 ], [ 0, %0 ]
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %15, i32 %16)
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
%21 = select i1 %20, i32 %19, i32 %18
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %1
%24 = load i32, i32* %2
%25 = select i1 %20, i32 %23, i32 %24
%26 = add nsw i32 %25, %14
%27 = call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2)
%28 = load i64, i64* @EOF
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %13
30: ; preds = %13, %0
%31 = phi i32 [ 0, %0 ], [ %26, %13 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %31)
%33 = call i32 @fclose(i32* %9)
ret i32 0
}