#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 /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printProgress(short);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
short strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main() {
  char buffer[4];
  short progress = 0;
  printf("+===================================================================="
         "==+\n"
         "|                            printProgress                           "
         "  |\n"
         "+===================================================================="
         "==+\n"
         "|              Copyright (C) 2011 William Breathitt Gray             "
         "  |\n"
         "+--------------------------------------------------------------------"
         "--+\n"
         "|Version: 1.0                                                        "
         "  |\n"
         "+--------------------------------------------------------------------"
         "--+\n"
         "|  This program comes with ABSOLUTELY NO WARRANTY. This is free      "
         "  |\n"
         "|  software, and you are welcome to redistribute it under certain    "
         "  |\n"
         "|  conditions; for further details, please refer to the GNU General  "
         "  |\n"
         "|  Public License provided with this program.                        "
         "  |\n"
         "+===================================================================="
         "==+\n"
         "+===================================================================="
         "==+\n\n");
  printf("Input a percentage:\n> ");
  fgets(buffer, sizeof(buffer), stdin);
  progress = strtoul(buffer, NULL, 0);
  printProgress(progress);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0x0,-0xa(%rbp)
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
lea    0x124f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <fgets@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %ax,-0xa(%rbp)
movswl -0xa(%rbp),%edi
call   1040 <printProgress@plt>
lea    0x120e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
lea    0xe88(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
movswl %ax,%edi
call   1060 <printProgress@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [951 x i8] c"+======================================================================+\0A| printProgress |\0A+======================================================================+\0A| Copyright (C) 2011 William Breathitt Gray |\0A+----------------------------------------------------------------------+\0A|Version: 1.0 |\0A+----------------------------------------------------------------------+\0A| This program comes with ABSOLUTELY NO WARRANTY. This is free |\0A| software, and you are welcome to redistribute it under certain |\0A| conditions; for further details, please refer to the GNU General |\0A| Public License provided with this program. |\0A+======================================================================+\0A+======================================================================+\0A\0A\00"
@.str.1 = [23 x i8] c"Input a percentage:\0A> \00"
@stdin = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca i16
store i32 0, i32* %1
store i16 0, i16* %3
%4 = call i32 @printf(i8* getelementptr inbounds ([951 x i8], [951 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 4, i32 %7)
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%10 = call signext i16 @strtoul(i8* %9, i32* null, i32 0)
store i16 %10, i16* %3
%11 = load i16, i16* %3
%12 = call i32 @printProgress(i16 signext %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"Input a percentage:\0A> \00"
@stdin = global i32 0
@str = [950 x i8] c"+======================================================================+\0A| printProgress |\0A+======================================================================+\0A| Copyright (C) 2011 William Breathitt Gray |\0A+----------------------------------------------------------------------+\0A|Version: 1.0 |\0A+----------------------------------------------------------------------+\0A| This program comes with ABSOLUTELY NO WARRANTY. This is free |\0A| software, and you are welcome to redistribute it under certain |\0A| conditions; for further details, please refer to the GNU General |\0A| Public License provided with this program. |\0A+======================================================================+\0A+======================================================================+\0A\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([950 x i8], [950 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %2, i32 4, i32 %5)
%7 = call signext i16 @strtoul(i8* nocapture %2, i32* null, i32 0)
%8 = call i32 @printProgress(i16 signext %7)
%9 = call i32 @putchar(i32 10)
ret i32 0
}