#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 atoi(char *);
char *decimal_to_binary(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  char *buffer = malloc(256);
  char *number = malloc(256);
  int num;
  char *pointer;
  if (number == NULL || buffer == NULL) {
    printf("Out of memory\n");
    return 1;
  }
  printf("Mata in ett tal du vill konvertera: ");
  fgets(number, 256, stdin);
  if (strlen(number) == 0) {
    printf("Invalid input\n");
    return 1;
  }
  number[strlen(number) - 1] = '\0';
  num = atoi(number);
  pointer = decimal_to_binary(num);
  printf("Bin\tOct\tDec\n");
  printf("%s\t%o\t%d\n", pointer, num, num);
  free(pointer);
  pointer = NULL;
  free(buffer);
  buffer = NULL;
  free(number);
  number = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b1 <main+0x41>
cmpq   $0x0,-0x10(%rbp)
jne    11cb <main+0x5b>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <main+0x145>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    121c <main+0xac>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <main+0x145>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <decimal_to_binary@plt>
mov    %rax,-0x28(%rbp)
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0x100,%edi
call   1080 <malloc@plt>
test   %r14,%r14
je     1245 <main+0xc5>
mov    %rax,%rbx
test   %rax,%rax
je     1245 <main+0xc5>
lea    0xe45(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     124e <main+0xce>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1090 <decimal_to_binary@plt>
mov    %rax,%r12
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe08(%rip),%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1260 <main+0xe0>
lea    0xdfd(%rip),%rdi
jmp    1255 <main+0xd5>
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory\0A\00"
@.str.1 = [37 x i8] c"Mata in ett tal du vill konvertera: \00"
@stdin = global i32 0
@.str.2 = [15 x i8] c"Invalid input\0A\00"
@.str.3 = [13 x i8] c"Bin\09Oct\09Dec\0A\00"
@.str.4 = [10 x i8] c"%s\09%o\09%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i8* @malloc(i32 256)
store i8* %6, i8** %2
%7 = call i8* @malloc(i32 256)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i8*, i8** %2
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10, %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %47
15: ; preds = %10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %3
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 256, i32 %18)
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %47
25: ; preds = %15
%26 = load i8*, i8** %3
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %3
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = call i8* @decimal_to_binary(i32 %34)
store i8* %35, i8** %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%37 = load i8*, i8** %5
%38 = load i32, i32* %4
%39 = load i32, i32* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %37, i32 %38, i32 %39)
%41 = load i8*, i8** %5
%42 = call i32 @free(i8* %41)
store i8* null, i8** %5
%43 = load i8*, i8** %2
%44 = call i32 @free(i8* %43)
store i8* null, i8** %2
%45 = load i8*, i8** %3
%46 = call i32 @free(i8* %45)
store i8* null, i8** %3
store i32 0, i32* %1
br label %47
47: ; preds = %25, %23, %13
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str.1 = [37 x i8] c"Mata in ett tal du vill konvertera: \00"
@stdin = global i32 0
@.str.4 = [10 x i8] c"%s\09%o\09%d\0A\00"
@str = [12 x i8] c"Bin\09Oct\09Dec\00"
@str.5 = [14 x i8] c"Invalid input\00"
@str.6 = [14 x i8] c"Out of memory\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%2 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%3 = icmp eq i8* %2, null
%4 = icmp eq i8* %1, null
%5 = or i1 %4, %3
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
br label %28
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = tail call i32 @fgets(i8* %2, i32 256, i32 %10)
%12 = tail call i32 @strlen(i8* %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
br label %28
16: ; preds = %8
%17 = tail call i32 @strlen(i8* %2)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %2, i64 %19
store i8 0, i8* %20
%21 = tail call i32 @atoi(i8* %2)
%22 = tail call i8* @decimal_to_binary(i32 %21)
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %22, i32 %21, i32 %21)
%25 = tail call i32 @free(i8* %22)
%26 = tail call i32 @free(i8* %1)
%27 = tail call i32 @free(i8* %2)
br label %28
28: ; preds = %16, %14, %6
%29 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 0, %16 ]
ret i32 %29
}