#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  int x, y, maior, menor, soma = 0;
  char fname[51];
  printf("Digite o nome completo do arquivo com extensão: ");
  scanf("%s", fname);
  FILE *arquivo;
  arquivo = fopen(fname, "r");
  if (arquivo == NULL) {
    printf("\nO arquivo %s não pôde ser aberto\n", fname);
    return 0;
  }
  fscanf(arquivo, "%d %d", &x, &y);
  while (!feof(arquivo)) {
    if (x >= y) {
      maior = x;
      menor = y;
    } else {
      maior = y;
      menor = x;
    }
    printf("Maior da linha: %d\n", maior);
    soma = soma + menor;
    fscanf(arquivo, "%d %d", &x, &y);
  }
  printf("A soma dos menores é: %d\n", soma);
  fclose(arquivo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xea3(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    11d1 <main+0x71>
lea    -0x50(%rbp),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1288 <main+0x128>
mov    -0x58(%rbp),%rdi
lea    0xe80(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   1050 <fscanf@plt>
mov    -0x58(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1207 <main+0xa7>
jmp    1267 <main+0x107>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1224 <main+0xc4>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1230 <main+0xd0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x58(%rbp),%rdi
lea    0xe07(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   1050 <fscanf@plt>
jmp    11e9 <main+0x89>
mov    -0x18(%rbp),%esi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe8b(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
call   1070 <scanf@plt>
lea    0xe9c(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     124e <main+0xee>
mov    %rax,%r14
lea    0xea8(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1234 <main+0xd4>
lea    0xe83(%rip),%r12
lea    0xc(%rsp),%r13
lea    0x8(%rsp),%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0xc(%rsp),%eax
mov    0x8(%rsp),%r15d
cmp    %r15d,%eax
mov    %eax,%esi
cmovl  %r15d,%esi
cmovl  %eax,%r15d
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    %r15d,%ebx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1050 <fscanf@plt>
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11f0 <main+0x90>
lea    0xe3b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    1261 <main+0x101>
lea    0xde2(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Digite o nome completo do arquivo com extens\C3\A3o: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [37 x i8] c"\0AO arquivo %s n\C3\A3o p\C3\B4de ser aberto\0A\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [20 x i8] c"Maior da linha: %d\0A\00"
@.str.6 = [27 x i8] c"A soma dos menores \C3\A9: %d\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 [51 x i8]
%8 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [51 x i8], [51 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 [51 x i8], [51 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
%14 = load i32*, i32** %8
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = getelementptr inbounds [51 x i8], [51 x i8]* %7, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %17)
store i32 0, i32* %1
br label %50
19: ; preds = %0
%20 = load i32*, i32** %8
%21 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %2, i32* %3)
br label %22
22: ; preds = %37, %19
%23 = load i32*, i32** %8
%24 = call i32 @feof(i32* %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br i1 %26, label %27, label %45
27: ; preds = %22
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = icmp sge i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* %2
store i32 %32, i32* %4
%33 = load i32, i32* %3
store i32 %33, i32* %5
br label %37
34: ; preds = %27
%35 = load i32, i32* %3
store i32 %35, i32* %4
%36 = load i32, i32* %2
store i32 %36, i32* %5
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %4
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %6
%41 = load i32, i32* %5
%42 = add nsw i32 %40, %41
store i32 %42, i32* %6
%43 = load i32*, i32** %8
%44 = call i32 @fscanf(i32* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %2, i32* %3)
br label %22
45: ; preds = %22
%46 = load i32, i32* %6
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %46)
%48 = load i32*, i32** %8
%49 = call i32 @fclose(i32* %48)
store i32 0, i32* %1
br label %50
50: ; preds = %45, %16
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [50 x i8] c"Digite o nome completo do arquivo com extens\C3\A3o: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [37 x i8] c"\0AO arquivo %s n\C3\A3o p\C3\B4de ser aberto\0A\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [20 x i8] c"Maior da linha: %d\0A\00"
@.str.6 = [27 x i8] c"A soma dos menores \C3\A9: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [51 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 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 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %33
13: ; preds = %0
%14 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %1, i32* %2)
%15 = call i32 @feof(i32* %9)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %13, %17
%18 = phi i32 [ %25, %17 ], [ 0, %13 ]
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
%22 = select i1 %21, i32 %20, i32 %19
%23 = select i1 %21, i32 %19, i32 %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%25 = add nsw i32 %23, %18
%26 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %1, i32* %2)
%27 = call i32 @feof(i32* %9)
%28 = icmp eq i32 %27, 0
br i1 %28, label %17, label %29
29: ; preds = %17, %13
%30 = phi i32 [ 0, %13 ], [ %25, %17 ]
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = call i32 @fclose(i32* %9)
br label %33
33: ; preds = %29, %11
ret i32 0
}