#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 /*<<< orphan*/ strcpy(char *, char *);
void ex1() {
  char nome[20], nomemaior[20];
  int quantprod = 0, quantvend = 0, estoque = 0, flag = 1, maior = 0;
  while (flag) {
    printf("Informe o nome do produto: ");
    scanf("%20s", nome);
    printf("Informe a quantidade produzida: ");
    scanf("%d", &quantprod);
    printf("Informe a quantidade vendida: ");
    scanf("%d", &quantvend);
    estoque = quantprod - quantvend;
    printf("\nProduto: %s\n\tProduzido: %d\n\tVendidos: %d\n\tEstoque: %d\n",
           nome, quantprod, quantvend, estoque);
    if (estoque < 50)
      printf("O estoque e menor que 50.\n");
    if (estoque > maior) {
      strcpy(nomemaior, nome);
      maior = estoque;
    }
    printf("Digite 0 para sair ou 1 para continuar.\n");
    scanf("%d", &flag);
  }
  printf("Produto com maior estoque: %s (Estoque:%d)\n", nomemaior, maior);
}


x86 assembly (clang, -O0):
<ex1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x1,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     1246 <ex1+0x116>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
lea    -0x44(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0x48(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x44(%rbp),%eax
sub    -0x48(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x20(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    -0x48(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x32,-0x4c(%rbp)
jge    1202 <ex1+0xd2>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jle    1221 <ex1+0xf1>
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x54(%rbp)
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0c(%rip),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
jmp    115b <ex1+0x2b>
lea    -0x40(%rbp),%rsi
mov    -0x54(%rbp),%edx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x1,0x4(%rsp)
lea    0x30(%rsp),%r13
lea    0xed0(%rip),%rbx
lea    0xf4f(%rip),%rbp
lea    0x4(%rsp),%r15
xor    %r12d,%r12d
jmp    11b0 <ex1+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
je     125b <ex1+0x11b>
lea    0xe49(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe57(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe4b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    %edx,%r14d
sub    %ecx,%r14d
lea    0xe46(%rip),%rdi
mov    %r13,%rsi
mov    %r14d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x31,%r14d
jg     123d <ex1+0xfd>
lea    0xeb8(%rip),%rdi
call   1040 <puts@plt>
cmp    %r12d,%r14d
jle    1190 <ex1+0x50>
lea    0x10(%rsp),%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r14d,%r12d
jmp    1190 <ex1+0x50>
lea    0xe3a(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Informe o nome do produto: \00"
@.str.1 = [5 x i8] c"%20s\00"
@.str.2 = [33 x i8] c"Informe a quantidade produzida: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [31 x i8] c"Informe a quantidade vendida: \00"
@.str.5 = [56 x i8] c"\0AProduto: %s\0A\09Produzido: %d\0A\09Vendidos: %d\0A\09Estoque: %d\0A\00"
@.str.6 = [27 x i8] c"O estoque e menor que 50.\0A\00"
@.str.7 = [41 x i8] c"Digite 0 para sair ou 1 para continuar.\0A\00"
@.str.8 = [44 x i8] c"Produto com maior estoque: %s (Estoque:%d)\0A\00"
define void @ex1() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 1, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %40, %0
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %43
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = sub nsw i32 %19, %20
store i32 %21, i32* %5
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* %22, i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* %5
%28 = icmp slt i32 %27, 50
br i1 %28, label %29, label %31
29: ; preds = %11
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %31
31: ; preds = %29, %11
%32 = load i32, i32* %5
%33 = load i32, i32* %7
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%38 = call i32 @strcpy(i8* %36, i8* %37)
%39 = load i32, i32* %5
store i32 %39, i32* %7
br label %40
40: ; preds = %35, %31
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
%42 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
br label %8
43: ; preds = %8
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%45 = load i32, i32* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i8* %44, i32 %45)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"Informe o nome do produto: \00"
@.str.1 = [5 x i8] c"%20s\00"
@.str.2 = [33 x i8] c"Informe a quantidade produzida: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [31 x i8] c"Informe a quantidade vendida: \00"
@.str.5 = [56 x i8] c"\0AProduto: %s\0A\09Produzido: %d\0A\09Vendidos: %d\0A\09Estoque: %d\0A\00"
@.str.8 = [44 x i8] c"Produto com maior estoque: %s (Estoque:%d)\0A\00"
@str = [40 x i8] c"Digite 0 para sair ou 1 para continuar.\00"
@str.9 = [26 x i8] c"O estoque e menor que 50.\00"
define void @ex1() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = bitcast i32* %5 to i8*
store i32 1, i32* %5
br label %11
11: ; preds = %0, %30
%12 = phi i32 [ 0, %0 ], [ %31, %30 ]
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = sub nsw i32 %19, %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* %6, i32 %19, i32 %20, i32 %21)
%23 = icmp slt i32 %21, 50
br i1 %23, label %24, label %26
24: ; preds = %11
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.9, i64 0, i64 0))
br label %26
26: ; preds = %24, %11
%27 = icmp sgt i32 %21, %12
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = call i32 @strcpy(i8* %7, i8* %6)
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ %21, %28 ], [ %12, %26 ]
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %11
36: ; preds = %30
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i8* %7, i32 %31)
ret void
}