#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*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int prodA = 0, prodB = 0, vendA = 0, vendB = 0;
  int cod, prod = 0;
  printf("Informe a quantidade inicial do produto A:\n");
  do {
    scanf("%d", &prodA);
  } while (prodA <= 0);
  printf("Informe a quantidade inicial do produto B:\n");
  do {
    scanf("%d", &prodB);
  } while (prodB <= 0);
  while (prodA > 0 || prodB > 0) {
    printf("Informe vendas:\n");
    scanf("%d %d", &cod, &prod);
    if (cod == 1) {
      if (prod > prodA || prod == 0) {
        puts("Venda nao registrada");
        printf("Estoque: A = %d B = %d\n", prodA, prodB);
      } else {
        puts("Venda registrada");
        prodA -= prod;
        printf("Estoque: A = %d B = %d\n", prodA, prodB);
        vendA++;
      }
    } else if (cod == 2) {
      if (prod > prodB || prod == 0) {
        puts("Venda nao registrada");
        printf("Estoque: A = %d B = %d\n", prodA, prodB);
      } else {
        prodB -= prod;
        puts("Venda registrada");
        printf("Estoque: A = %d B = %d\n", prodA, prodB);
        vendB++;
      }
    }
  }
  puts("\nRelatorio:");
  printf("Numero de registos de venda o produto A: %d\n", vendA);
  printf("Numero de registos 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    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xef5(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    1170 <main+0x40>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    119a <main+0x6a>
jmp    11bb <main+0x8b>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x1d(%rbp)
jg     11d4 <main+0xa4>
cmpl   $0x0,-0xc(%rbp)
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11e4 <main+0xb4>
jmp    130e <main+0x1de>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe70(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1286 <main+0x156>
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1228 <main+0xf8>
cmpl   $0x0,-0x1c(%rbp)
jne    124d <main+0x11d>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1281 <main+0x151>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1309 <main+0x1d9>
cmpl   $0x2,-0x18(%rbp)
jne    1304 <main+0x1d4>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     12a6 <main+0x176>
cmpl   $0x0,-0x1c(%rbp)
jne    12cb <main+0x19b>
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ff <main+0x1cf>
mov    -0x1c(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
lea    0xdbf(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1304 <main+0x1d4>
jmp    1309 <main+0x1d9>
jmp    11bb <main+0x8b>
lea    0xd98(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
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    0xf4d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9a(%rip),%rbx
lea    0xc(%rsp),%rbp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1170 <main+0x40>
lea    0xf4a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6c(%rip),%rbx
lea    0x8(%rsp),%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11a0 <main+0x70>
lea    0xf45(%rip),%r12
lea    0xe3e(%rip),%r13
lea    0x14(%rsp),%rbx
lea    0x10(%rsp),%rbp
xor    %r14d,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    $0x2,%eax
je     1250 <main+0x120>
cmp    $0x1,%eax
jne    12b2 <main+0x182>
mov    0x10(%rsp),%eax
test   %eax,%eax
je     1290 <main+0x160>
cmp    0xc(%rsp),%eax
jg     1290 <main+0x160>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
sub    0x10(%rsp),%esi
mov    %esi,0xc(%rsp)
mov    0x8(%rsp),%edx
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
jmp    12b2 <main+0x182>
nopl   0x0(%rax)
mov    0x10(%rsp),%eax
test   %eax,%eax
je     1290 <main+0x160>
mov    0x8(%rsp),%ecx
sub    %eax,%ecx
jl     1290 <main+0x160>
mov    %ecx,0x8(%rsp)
lea    0xdc8(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xd9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14d
jmp    12b2 <main+0x182>
nopl   0x0(%rax)
lea    0xd6f(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xd70(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jg     11e0 <main+0xb0>
cmpl   $0x0,0x8(%rsp)
jg     11e0 <main+0xb0>
lea    0xd75(%rip),%rdi
call   1030 <puts@plt>
lea    0xd75(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd91(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
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 = [3 x i8] c"%d\00"
@.str.2 = [44 x i8] c"Informe a quantidade inicial do produto B:\0A\00"
@.str.3 = [17 x i8] c"Informe vendas:\0A\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [21 x i8] c"Venda nao registrada\00"
@.str.6 = [24 x i8] c"Estoque: A = %d B = %d\0A\00"
@.str.7 = [17 x i8] c"Venda registrada\00"
@.str.8 = [12 x i8] c"\0ARelatorio:\00"
@.str.9 = [45 x i8] c"Numero de registos de venda o produto A: %d\0A\00"
@.str.10 = [45 x i8] c"Numero de registos 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))
br label %9
9: ; preds = %11, %0
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %11
11: ; preds = %9
%12 = load i32, i32* %2
%13 = icmp sle i32 %12, 0
br i1 %13, label %9, label %14
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %18, %14
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %18
18: ; preds = %16
%19 = load i32, i32* %3
%20 = icmp sle i32 %19, 0
br i1 %20, label %16, label %21
21: ; preds = %18
br label %22
22: ; preds = %85, %21
%23 = load i32, i32* %2
%24 = icmp sgt i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, 0
br label %28
28: ; preds = %25, %22
%29 = phi i1 [ true, %22 ], [ %27, %25 ]
br i1 %29, label %30, label %86
30: ; preds = %28
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %6, i32* %7)
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %58
35: ; preds = %30
%36 = load i32, i32* %7
%37 = load i32, i32* %2
%38 = icmp sgt i32 %36, %37
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39, %35
%43 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* %2
%45 = load i32, i32* %3
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %44, i32 %45)
br label %57
47: ; preds = %39
%48 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%49 = load i32, i32* %7
%50 = load i32, i32* %2
%51 = sub nsw i32 %50, %49
store i32 %51, i32* %2
%52 = load i32, i32* %2
%53 = load i32, i32* %3
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %52, i32 %53)
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %57
57: ; preds = %47, %42
br label %85
58: ; preds = %30
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, 2
br i1 %60, label %61, label %84
61: ; preds = %58
%62 = load i32, i32* %7
%63 = load i32, i32* %3
%64 = icmp sgt i32 %62, %63
br i1 %64, label %68, label %65
65: ; preds = %61
%66 = load i32, i32* %7
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %65, %61
%69 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%70 = load i32, i32* %2
%71 = load i32, i32* %3
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %70, i32 %71)
br label %83
73: ; preds = %65
%74 = load i32, i32* %7
%75 = load i32, i32* %3
%76 = sub nsw i32 %75, %74
store i32 %76, i32* %3
%77 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%78 = load i32, i32* %2
%79 = load i32, i32* %3
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %78, i32 %79)
%81 = load i32, i32* %5
%82 = add nsw i32 %81, 1
store i32 %82, i32* %5
br label %83
83: ; preds = %73, %68
br label %84
84: ; preds = %83, %58
br label %85
85: ; preds = %84, %57
br label %22
86: ; preds = %28
%87 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%88 = load i32, i32* %4
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0), i32 %88)
%90 = load i32, i32* %5
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.10, i64 0, i64 0), i32 %90)
ret i32 0
}

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