#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 */
void *atoi(char *);
int /*<<< orphan*/ dump_digits(char const *, int, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int strtod(char *, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int64_t pos, n;
  const char *filename;
  int base;
  if (argc < 4) {
    printf("usage: tpidump filename base pos [nb_digits]\n"
           "\n"
           "Dump digits using tpi internal floating point format\n"
           "Example to display 50 digits starting from position 1:\n"
           "tpidump pi_base10 10 1\n");
    exit(1);
  }
  filename = argv[1];
  base = atoi(argv[2]);
  pos = strtod(argv[3], NULL);
  if (argc >= 5)
    n = atoi(argv[4]);
  else
    n = 50;
  dump_digits(filename, base, pos, n);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1186 <main+0x36>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x5,-0x8(%rbp)
jl     11d5 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    11dc <main+0x8c>
movl   $0x32,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1050 <dump_digits@plt>
lea    0xebb(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x3,%edi
jle    11c9 <main+0x69>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rax,%r15
mov    0x18(%rbx),%rdi
xor    %esi,%esi
call   1050 <strtod@plt>
mov    %eax,%r12d
mov    $0x32,%ecx
cmp    $0x4,%ebp
je     11a6 <main+0x46>
mov    0x20(%rbx),%rdi
call   1070 <atoi@plt>
mov    %rax,%rcx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
call   1060 <dump_digits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [178 x i8] c"usage: tpidump filename base pos [nb_digits]\0A\0ADump digits using tpi internal floating point format\0AExample to display 50 digits starting from position 1:\0Atpidump pi_base10 10 1\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([178 x i8], [178 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %8
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i8* @atoi(i8* %21)
%23 = ptrtoint i8* %22 to i32
store i32 %23, i32* %9
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
%27 = call i32 @strtod(i8* %26, i32* null)
store i32 %27, i32* %6
%28 = load i32, i32* %4
%29 = icmp sge i32 %28, 5
br i1 %29, label %30, label %36
30: ; preds = %15
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 4
%33 = load i8*, i8** %32
%34 = call i8* @atoi(i8* %33)
%35 = ptrtoint i8* %34 to i32
store i32 %35, i32* %7
br label %37
36: ; preds = %15
store i32 50, i32* %7
br label %37
37: ; preds = %36, %30
%38 = load i8*, i8** %8
%39 = load i32, i32* %9
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = call i32 @dump_digits(i8* %38, i32 %39, i32 %40, i32 %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@str = [177 x i8] c"usage: tpidump filename base pos [nb_digits]\0A\0ADump digits using tpi internal floating point format\0AExample to display 50 digits starting from position 1:\0Atpidump pi_base10 10 1\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([177 x i8], [177 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i8* @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32 @strtod(i8* nocapture %14, i32* null)
%16 = icmp eq i32 %0, 4
br i1 %16, label %23, label %17
17: ; preds = %7
%18 = getelementptr inbounds i8*, i8** %1, i64 4
%19 = load i8*, i8** %18
%20 = tail call i8* @atoi(i8* %19)
%21 = ptrtoint i8* %20 to i64
%22 = trunc i64 %21 to i32
br label %23
23: ; preds = %7, %17
%24 = phi i32 [ %22, %17 ], [ 50, %7 ]
%25 = ptrtoint i8* %12 to i64
%26 = trunc i64 %25 to i32
%27 = tail call i32 @dump_digits(i8* %9, i32 %26, i32 %15, i32 %24)
%28 = tail call i32 @putchar(i32 10)
ret i32 0
}