#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 */
typedef int int64_t;

/* Variables and functions */
int dc(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int64_t *ptr = malloc(100 * sizeof(int64_t));
  if (ptr == NULL) {
    printf("Couldn't allocate memory");
    return 1;
  }
  int64_t exit_code = dc(ptr);
  switch (exit_code) {
  case 0:
    printf("Exited normally.\n");
    break;
  default:
    printf("Invalid character '%c'. Accepted: 0123456789pdx+-*/%%^.\n",
           (int)exit_code);
    break;
  }
  return exit_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x190,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1172 <main+0x42>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b8 <main+0x88>
mov    -0x10(%rbp),%rdi
call   1040 <dc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
test   %eax,%eax
jne    11a1 <main+0x71>
jmp    118e <main+0x5e>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <main+0x82>
mov    -0x14(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x190,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1170 <main+0x30>
mov    %rax,%rdi
call   1050 <dc@plt>
test   %eax,%eax
je     1185 <main+0x45>
mov    %eax,%ebx
lea    0xeb4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1193 <main+0x53>
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
jmp    1193 <main+0x53>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Couldn't allocate memory\00"
@.str.1 = [18 x i8] c"Exited normally.\0A\00"
@.str.2 = [57 x i8] c"Invalid character '%c'. Accepted: 0123456789pdx+-*/%%^.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @malloc(i32 400)
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %20
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call i32 @dc(i32* %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
switch i32 %12, label %15 [
i32 0, label %13
]
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %18
15: ; preds = %9
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %13
%19 = load i32, i32* %3
store i32 %19, i32* %1
br label %20
20: ; preds = %18, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [25 x i8] c"Couldn't allocate memory\00"
@.str.2 = [57 x i8] c"Invalid character '%c'. Accepted: 0123456789pdx+-*/%%^.\0A\00"
@str = [17 x i8] c"Exited normally.\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 400)
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %12
5: ; preds = %0
%6 = tail call i32 @dc(i32* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %12
10: ; preds = %5
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i32 %6)
br label %12
12: ; preds = %8, %10, %3
%13 = phi i32 [ 1, %3 ], [ %6, %10 ], [ 0, %8 ]
ret i32 %13
}