#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
*DIS_le_codigo(void) {
  char *cod1 = (char *)calloc(8, sizeof(char));
  char *cod2 = (char *)calloc(5, sizeof(char));
  if (cod1 == NULL) {
    printf("Memoria insuficiente!\n\n");
    exit(1);
  }
  strcat(cod1, "inf");
  printf("\nDigite o codigo numerico da disciplina:\n");
  scanf("%4s", cod2);
  while ((int)cod2[0] < 48 || (int)cod2[0] > 57 || (int)cod2[1] < 48 ||
         (int)cod2[1] > 57 || (int)cod2[2] < 48 || (int)cod2[2] > 57 ||
         (int)cod2[3] < 48 || (int)cod2[3] > 57 || strlen(cod2) < 4) {
    printf("Selecione caracteres validos (0 >= x <=9):");
    scanf("%4s", cod2);
  }
  strcat(cod1, cod2);
  free(cod2);
  return cod1;
}


x86 assembly (clang, -O0):
<DIS_le_codigo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x8,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x5,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11bf <DIS_le_codigo+0x4f>
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <strcat@plt>
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0x11(%rbp)
jl     12ab <DIS_le_codigo+0x13b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x39,%ecx
mov    %al,-0x11(%rbp)
jg     12ab <DIS_le_codigo+0x13b>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0x11(%rbp)
jl     12ab <DIS_le_codigo+0x13b>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%ecx
mov    $0x1,%al
cmp    $0x39,%ecx
mov    %al,-0x11(%rbp)
jg     12ab <DIS_le_codigo+0x13b>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0x11(%rbp)
jl     12ab <DIS_le_codigo+0x13b>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%ecx
mov    $0x1,%al
cmp    $0x39,%ecx
mov    %al,-0x11(%rbp)
jg     12ab <DIS_le_codigo+0x13b>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0x11(%rbp)
jl     12ab <DIS_le_codigo+0x13b>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%ecx
mov    $0x1,%al
cmp    $0x39,%ecx
mov    %al,-0x11(%rbp)
jg     12ab <DIS_le_codigo+0x13b>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    12bb <DIS_le_codigo+0x14b>
jmp    12dc <DIS_le_codigo+0x16c>
lea    0xd88(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xd74(%rip),%rdi
call   1070 <scanf@plt>
jmp    11eb <DIS_le_codigo+0x7b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DIS_le_codigo>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x8,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
mov    $0x5,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
test   %r14,%r14
je     1259 <DIS_le_codigo+0xd9>
mov    %rax,%rbx
lea    0xe44(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcat@plt>
lea    0xe68(%rip),%rdi
call   1040 <puts@plt>
lea    0xe2d(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
lea    0xe1f(%rip),%r12
jmp    1203 <DIS_le_codigo+0x83>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
movzbl (%rbx),%eax
add    $0xc6,%al
cmp    $0xf6,%al
jb     11f0 <DIS_le_codigo+0x70>
movzbl 0x1(%rbx),%eax
add    $0xc6,%al
cmp    $0xf6,%al
jb     11f0 <DIS_le_codigo+0x70>
movzbl 0x2(%rbx),%eax
add    $0xc6,%al
cmp    $0xf6,%al
jb     11f0 <DIS_le_codigo+0x70>
movzbl 0x3(%rbx),%eax
add    $0xc6,%al
cmp    $0xf6,%al
jb     11f0 <DIS_le_codigo+0x70>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x3,%eax
jle    11f0 <DIS_le_codigo+0x70>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdfc(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Memoria insuficiente!\0A\0A\00"
@.str.1 = [4 x i8] c"inf\00"
@.str.2 = [42 x i8] c"\0ADigite o codigo numerico da disciplina:\0A\00"
@.str.3 = [4 x i8] c"%4s\00"
@.str.4 = [43 x i8] c"Selecione caracteres validos (0 >= x <=9):\00"
define i32* @DIS_le_codigo() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i64 @calloc(i32 8, i32 1)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %1
%5 = call i64 @calloc(i32 5, i32 1)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %2
%7 = load i8*, i8** %1
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i8*, i8** %1
%14 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%16 = load i8*, i8** %2
%17 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %72, %12
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp slt i32 %22, 48
br i1 %23, label %70, label %24
24: ; preds = %18
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp sgt i32 %28, 57
br i1 %29, label %70, label %30
30: ; preds = %24
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp slt i32 %34, 48
br i1 %35, label %70, label %36
36: ; preds = %30
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp sgt i32 %40, 57
br i1 %41, label %70, label %42
42: ; preds = %36
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i64 2
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp slt i32 %46, 48
br i1 %47, label %70, label %48
48: ; preds = %42
%49 = load i8*, i8** %2
%50 = getelementptr inbounds i8, i8* %49, i64 2
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp sgt i32 %52, 57
br i1 %53, label %70, label %54
54: ; preds = %48
%55 = load i8*, i8** %2
%56 = getelementptr inbounds i8, i8* %55, i64 3
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp slt i32 %58, 48
br i1 %59, label %70, label %60
60: ; preds = %54
%61 = load i8*, i8** %2
%62 = getelementptr inbounds i8, i8* %61, i64 3
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp sgt i32 %64, 57
br i1 %65, label %70, label %66
66: ; preds = %60
%67 = load i8*, i8** %2
%68 = call i32 @strlen(i8* %67)
%69 = icmp slt i32 %68, 4
br label %70
70: ; preds = %66, %60, %54, %48, %42, %36, %30, %24, %18
%71 = phi i1 [ true, %60 ], [ true, %54 ], [ true, %48 ], [ true, %42 ], [ true, %36 ], [ true, %30 ], [ true, %24 ], [ true, %18 ], [ %69, %66 ]
br i1 %71, label %72, label %76
72: ; preds = %70
%73 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%74 = load i8*, i8** %2
%75 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %74)
br label %18
76: ; preds = %70
%77 = load i8*, i8** %1
%78 = load i8*, i8** %2
%79 = call i32 @strcat(i8* %77, i8* %78)
%80 = load i8*, i8** %2
%81 = call i32 @free(i8* %80)
%82 = load i8*, i8** %1
%83 = bitcast i8* %82 to i32*
ret i32* %83
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"inf\00"
@.str.3 = [4 x i8] c"%4s\00"
@.str.4 = [43 x i8] c"Selecione caracteres validos (0 >= x <=9):\00"
@str = [41 x i8] c"\0ADigite o codigo numerico da disciplina:\00"
@str.5 = [23 x i8] c"Memoria insuficiente!\0A\00"
define i32* @DIS_le_codigo() {
%1 = tail call i64 @calloc(i32 8, i32 1)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i64 @calloc(i32 5, i32 1)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %1, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%13 = getelementptr inbounds i8, i8* %4, i64 1
%14 = getelementptr inbounds i8, i8* %4, i64 2
%15 = getelementptr inbounds i8, i8* %4, i64 3
br label %16
16: ; preds = %35, %9
%17 = load i8, i8* %4
%18 = add i8 %17, -58
%19 = icmp ult i8 %18, -10
br i1 %19, label %35, label %20
20: ; preds = %16
%21 = load i8, i8* %13
%22 = add i8 %21, -58
%23 = icmp ult i8 %22, -10
br i1 %23, label %35, label %24
24: ; preds = %20
%25 = load i8, i8* %14
%26 = add i8 %25, -58
%27 = icmp ult i8 %26, -10
br i1 %27, label %35, label %28
28: ; preds = %24
%29 = load i8, i8* %15
%30 = add i8 %29, -58
%31 = icmp ult i8 %30, -10
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = tail call i32 @strlen(i8* %4)
%34 = icmp slt i32 %33, 4
br i1 %34, label %35, label %38
35: ; preds = %16, %20, %24, %28, %32
%36 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%37 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %16
38: ; preds = %32
%39 = tail call i32 @strcat(i8* %2, i8* %4)
%40 = tail call i32 @free(i8* %4)
%41 = inttoptr i64 %1 to i32*
ret i32* %41
}