#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*/ *gets(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int valcgc(char *);
main() {
  signed char str[100];
  strcpy(str, "63005573000128");
  printf("%s retorno de valcgc = %d\n", str, valcgc(str));
  strcpy(str, "00163672000118");
  printf("%s retorno de valcgc = %d\n", str, valcgc(str));
  while (gets(str) != NULL) {
    if (str[0] == 0)
      break;
    printf("%s retorno de valcgc = %d\n", str, valcgc(str));
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <valcgc@plt>
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <valcgc@plt>
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1050 <gets@plt>
cmp    $0x0,%rax
je     120b <main+0xcb>
movsbl -0x70(%rbp),%eax
cmp    $0x0,%eax
jne    11dd <main+0x9d>
jmp    120b <main+0xcb>
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <valcgc@plt>
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
jmp    11b8 <main+0x78>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xeb2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <valcgc@plt>
lea    0xea7(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <valcgc@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
test   %rax,%rax
je     11e8 <main+0xa8>
cmpb   $0x0,(%rsp)
je     11e8 <main+0xa8>
mov    %rsp,%rbx
lea    0xe59(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <valcgc@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
test   %rax,%rax
je     11e8 <main+0xa8>
cmpb   $0x0,(%rsp)
jne    11c0 <main+0x80>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"63005573000128\00"
@.str.1 = [27 x i8] c"%s retorno de valcgc = %d\0A\00"
@.str.2 = [15 x i8] c"00163672000118\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
store i32 0, i32* %1
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = call i32 @valcgc(i8* %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %5, i32 %7)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = call i32 @valcgc(i8* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %13)
br label %15
15: ; preds = %25, %0
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%17 = call i32* @gets(i8* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %30
25: ; preds = %19
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%28 = call i32 @valcgc(i8* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %28)
br label %15
30: ; preds = %24, %15
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"63005573000128\00"
@.str.1 = [27 x i8] c"%s retorno de valcgc = %d\0A\00"
@.str.2 = [15 x i8] c"00163672000118\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @valcgc(i8* %2)
%5 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %4)
%6 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @valcgc(i8* %2)
%8 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %7)
%9 = call i32* @gets(i8* %2)
%10 = icmp eq i32* %9, null
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 0
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %22, label %14
14: ; preds = %0, %14
%15 = call i32 @valcgc(i8* %2)
%16 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %15)
%17 = call i32* @gets(i8* %2)
%18 = icmp eq i32* %17, null
%19 = load i8, i8* %2
%20 = icmp eq i8 %19, 0
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %22, label %14
22: ; preds = %14, %0
ret i32 0
}