#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*/ inicializa_estoque(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int registra_venda(int *, int);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main() {
  int prodA = 0, prodB = 0, vendA = 0, vendB = 0;
  int cod, valor_desconto = 0;
  printf("Informe a quantidade inicial do produto A:\n");
  inicializa_estoque(&prodA);
  printf("Informe a quantidade inicial do produto B:\n");
  inicializa_estoque(&prodB);
  while (prodA > 0 || prodB > 0) {
    printf("Informe vendas:\n");
    scanf("%d %d", &cod, &valor_desconto);
    if (cod == 1) {
      if (registra_venda(&prodA, valor_desconto) == 1) {
        puts("Venda registrada");
        printf("Estoque A:%d\tEstoque B:%d\n", prodA, prodB);
        vendA++;
      } else {
        puts("Venda nao registrada");
        printf("Estoque A:%d\tEstoque B:%d\n", prodA, prodB);
      }
    }
    if (cod == 2) {
      if (registra_venda(&prodB, valor_desconto) == 1) {
        puts("Venda registrada");
        printf(" Estoque A:%d\tEstoque B:%d\n", prodA, prodB);
        vendB++;
      } else {
        puts("Venda nao registrada");
        printf("Estoque A:%d\tEstoque B:%d\n", prodA, prodB);
      }
    }
    puts("\nRelatorio:");
    printf("Numero de registros de venda o produto A: %d\n", vendA);
    printf("Numero de registros de venda o produto B: %d\n", vendB);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1070 <inicializa_estoque@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1070 <inicializa_estoque@plt>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x1d(%rbp)
jg     11c9 <main+0x79>
cmpl   $0x0,-0xc(%rbp)
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11d9 <main+0x89>
jmp    1312 <main+0x1c2>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7b(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
jne    126d <main+0x11d>
mov    -0x1c(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   1050 <registra_venda@plt>
cmp    $0x1,%eax
jne    1248 <main+0xf8>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1268 <main+0x118>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126d <main+0x11d>
cmpl   $0x2,-0x18(%rbp)
jne    12df <main+0x18f>
mov    -0x1c(%rbp),%esi
lea    -0xc(%rbp),%rdi
call   1050 <registra_venda@plt>
cmp    $0x1,%eax
jne    12ba <main+0x16a>
lea    0xddc(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12da <main+0x18a>
lea    0xdbf(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12df <main+0x18f>
lea    0xdcb(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b0 <main+0x60>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xf33(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   1070 <inicializa_estoque@plt>
lea    0xf48(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <inicializa_estoque@plt>
cmpl   $0x0,0xc(%rsp)
jg     11b4 <main+0x64>
cmpl   $0x0,0x8(%rsp)
jle    131a <main+0x1ca>
lea    0x10(%rsp),%rbx
lea    0xe88(%rip),%rbp
lea    0xe8d(%rip),%r13
lea    0xeb4(%rip),%r14
xor    %r15d,%r15d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xf1f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0d(%rip),%rdi
lea    0x14(%rsp),%rsi
mov    %rbx,%rdx
call   1060 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    $0x1,%eax
jne    1276 <main+0x126>
mov    0x10(%rsp),%esi
lea    0xc(%rsp),%rdi
call   1050 <registra_venda@plt>
cmp    $0x1,%eax
jne    1250 <main+0x100>
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12d
jmp    1272 <main+0x122>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xdc0(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xdc2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%eax
cmp    $0x2,%eax
jne    12e2 <main+0x192>
mov    0x10(%rsp),%esi
lea    0x8(%rsp),%rdi
call   1050 <registra_venda@plt>
cmp    $0x1,%eax
jne    12c0 <main+0x170>
lea    0xd71(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xd83(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
jmp    12e2 <main+0x192>
cs nopw 0x0(%rax,%rax,1)
lea    0xd50(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xd52(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jg     11e0 <main+0x90>
cmpl   $0x0,0x8(%rsp)
jg     11e0 <main+0x90>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Informe a quantidade inicial do produto A:\0A\00"
@.str.1 = [44 x i8] c"Informe a quantidade inicial do produto B:\0A\00"
@.str.2 = [17 x i8] c"Informe vendas:\0A\00"
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [17 x i8] c"Venda registrada\00"
@.str.5 = [27 x i8] c"Estoque A:%d\09Estoque B:%d\0A\00"
@.str.6 = [21 x i8] c"Venda nao registrada\00"
@.str.7 = [28 x i8] c" Estoque A:%d\09Estoque B:%d\0A\00"
@.str.8 = [12 x i8] c"\0ARelatorio:\00"
@.str.9 = [46 x i8] c"Numero de registros de venda o produto A: %d\0A\00"
@.str.10 = [46 x i8] c"Numero de registros de venda o produto B: %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 i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @inicializa_estoque(i32* %2)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @inicializa_estoque(i32* %3)
br label %12
12: ; preds = %62, %0
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ true, %12 ], [ %17, %15 ]
br i1 %19, label %20, label %68
20: ; preds = %18
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %6, i32* %7)
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %42
25: ; preds = %20
%26 = load i32, i32* %7
%27 = call i32 @registra_venda(i32* %2, i32 %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 %32)
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %41
36: ; preds = %25
%37 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %38, i32 %39)
br label %41
41: ; preds = %36, %29
br label %42
42: ; preds = %41, %20
%43 = load i32, i32* %6
%44 = icmp eq i32 %43, 2
br i1 %44, label %45, label %62
45: ; preds = %42
%46 = load i32, i32* %7
%47 = call i32 @registra_venda(i32* %3, i32 %46)
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%51 = load i32, i32* %2
%52 = load i32, i32* %3
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %51, i32 %52)
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %61
56: ; preds = %45
%57 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%58 = load i32, i32* %2
%59 = load i32, i32* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %58, i32 %59)
br label %61
61: ; preds = %56, %49
br label %62
62: ; preds = %61, %42
%63 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%64 = load i32, i32* %4
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0), i32 %64)
%66 = load i32, i32* %5
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i32 %66)
br label %12
68: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [17 x i8] c"Venda registrada\00"
@.str.5 = [27 x i8] c"Estoque A:%d\09Estoque B:%d\0A\00"
@.str.6 = [21 x i8] c"Venda nao registrada\00"
@.str.7 = [28 x i8] c" Estoque A:%d\09Estoque B:%d\0A\00"
@.str.8 = [12 x i8] c"\0ARelatorio:\00"
@.str.9 = [46 x i8] c"Numero de registros de venda o produto A: %d\0A\00"
@.str.10 = [46 x i8] c"Numero de registros de venda o produto B: %d\0A\00"
@str = [43 x i8] c"Informe a quantidade inicial do produto A:\00"
@str.11 = [43 x i8] c"Informe a quantidade inicial do produto B:\00"
@str.12 = [16 x i8] c"Informe vendas:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%10 = call i32 @inicializa_estoque(i32* %1)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.11, i64 0, i64 0))
%12 = call i32 @inicializa_estoque(i32* %2)
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 0
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 0
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %72
18: ; preds = %0, %62
%19 = phi i32 [ %63, %62 ], [ 0, %0 ]
%20 = phi i32 [ %45, %62 ], [ 0, %0 ]
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.12, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4)
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %43
25: ; preds = %18
%26 = load i32, i32* %4
%27 = call i32 @registra_venda(i32* %1, i32 %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* %1
%32 = load i32, i32* %2
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 %32)
%34 = add nsw i32 %20, 1
br label %40
35: ; preds = %25
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%37 = load i32, i32* %1
%38 = load i32, i32* %2
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %37, i32 %38)
br label %40
40: ; preds = %35, %29
%41 = phi i32 [ %20, %35 ], [ %34, %29 ]
%42 = load i32, i32* %3
br label %43
43: ; preds = %40, %18
%44 = phi i32 [ %42, %40 ], [ %23, %18 ]
%45 = phi i32 [ %41, %40 ], [ %20, %18 ]
%46 = icmp eq i32 %44, 2
br i1 %46, label %47, label %62
47: ; preds = %43
%48 = load i32, i32* %4
%49 = call i32 @registra_venda(i32* %2, i32 %48)
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %57
51: ; preds = %47
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* %1
%54 = load i32, i32* %2
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %53, i32 %54)
%56 = add nsw i32 %19, 1
br label %62
57: ; preds = %47
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%59 = load i32, i32* %1
%60 = load i32, i32* %2
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %59, i32 %60)
br label %62
62: ; preds = %51, %57, %43
%63 = phi i32 [ %56, %51 ], [ %19, %57 ], [ %19, %43 ]
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0), i32 %45)
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i32 %63)
%67 = load i32, i32* %1
%68 = icmp sgt i32 %67, 0
%69 = load i32, i32* %2
%70 = icmp sgt i32 %69, 0
%71 = select i1 %68, i1 true, i1 %70
br i1 %71, label %18, label %72
72: ; preds = %62, %0
ret i32 0
}