#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void ex5() {
  int num, maior = 0, menor = 0, first = -1;
  while (1) {
    printf("Informe um numero [0 para encerrar]: ");
    scanf("%d", &num);
    if (!num)
      break;
    else if (num > 0) {
      if (num > maior)
        maior = num;
      if (menor > num || (!++first))
        menor = num;
    } else
      printf("Voce digitou um numero negativo.\n");
  }
  printf("Maior numero positivo:\t%d\n", maior);
  printf("Menor numero positivo:\t%d\n", menor);
}


x86 assembly (clang, -O0):
<ex5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
jne    116a <ex5+0x4a>
jmp    11c7 <ex5+0xa7>
cmpl   $0x0,-0x4(%rbp)
jle    11af <ex5+0x8f>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1186 <ex5+0x66>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11a4 <ex5+0x84>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    11aa <ex5+0x8a>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11bd <ex5+0x9d>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c2 <ex5+0xa2>
jmp    113d <ex5+0x1d>
mov    -0x8(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex5>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
mov    $0x0,%ebp
test   %eax,%eax
je     11e0 <ex5+0xb0>
mov    $0xffffffff,%r13d
lea    0xe8a(%rip),%r14
lea    0xea9(%rip),%r15
lea    0x4(%rsp),%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    11b2 <ex5+0x82>
nopl   0x0(%rax,%rax,1)
mov    %r13d,%ecx
mov    %eax,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     11e0 <ex5+0xb0>
test   %eax,%eax
jle    11d0 <ex5+0xa0>
cmp    %ebx,%eax
cmovg  %eax,%ebx
cmp    %eax,%ebp
jg     1190 <ex5+0x60>
xor    %ecx,%ecx
inc    %r13d
jne    11dc <ex5+0xac>
mov    %ecx,%r13d
jmp    1193 <ex5+0x63>
nopl   0x0(%rax,%rax,1)
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
jmp    1193 <ex5+0x63>
lea    0xe42(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Informe um numero [0 para encerrar]: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"Voce digitou um numero negativo.\0A\00"
@.str.3 = [27 x i8] c"Maior numero positivo:\09%d\0A\00"
@.str.4 = [27 x i8] c"Menor numero positivo:\09%d\0A\00"
define void @ex5() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %3
store i32 -1, i32* %4
br label %5
5: ; preds = %0, %34
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %5
br label %35
11: ; preds = %5
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i32, i32* %1
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* %3
%22 = load i32, i32* %1
%23 = icmp sgt i32 %21, %22
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24, %20
%29 = load i32, i32* %1
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %24
br label %33
31: ; preds = %11
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %30
br label %34
34: ; preds = %33
br label %5
35: ; preds = %10
%36 = load i32, i32* %2
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %38)
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"Informe um numero [0 para encerrar]: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [27 x i8] c"Maior numero positivo:\09%d\0A\00"
@.str.4 = [27 x i8] c"Menor numero positivo:\09%d\0A\00"
@str = [33 x i8] c"Voce digitou um numero negativo.\00"
define void @ex5() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %32, label %7
7: ; preds = %0, %24
%8 = phi i32 [ %30, %24 ], [ %5, %0 ]
%9 = phi i32 [ %27, %24 ], [ -1, %0 ]
%10 = phi i32 [ %26, %24 ], [ 0, %0 ]
%11 = phi i32 [ %25, %24 ], [ 0, %0 ]
%12 = icmp sgt i32 %8, 0
br i1 %12, label %13, label %22
13: ; preds = %7
%14 = icmp sgt i32 %8, %11
%15 = select i1 %14, i32 %8, i32 %11
%16 = icmp sgt i32 %10, %8
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = add nsw i32 %9, 1
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17, %13
%21 = phi i32 [ %9, %13 ], [ 0, %17 ]
br label %24
22: ; preds = %7
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %20, %17
%25 = phi i32 [ %15, %20 ], [ %15, %17 ], [ %11, %22 ]
%26 = phi i32 [ %8, %20 ], [ %10, %17 ], [ %10, %22 ]
%27 = phi i32 [ %21, %20 ], [ %18, %17 ], [ %9, %22 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%30 = load i32, i32* %1
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %7
32: ; preds = %24, %0
%33 = phi i32 [ 0, %0 ], [ %25, %24 ]
%34 = phi i32 [ 0, %0 ], [ %26, %24 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %34)
ret void
}