#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 fixed_to_float(int, int, int *);
int float_to_fixed(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int read_fixed(char *, int, int);
int read_float(char *, int, int *, int *);
int show_fixed(char *, int, int, int);
int show_float(char *, int, int, int);
int strlen(char *);
int main(int argc, char **argv) {
  char buf[64] = {0};
  if (argc >= 2) {
    int exponent, mantissa;
    char *arg = argv[1];
    int len = strlen(arg);
    int ret = read_float(arg, len, &exponent, &mantissa);
    printf("read_float(\"%s\", %d, %d, %d) = %d\n", arg, len, exponent,
           mantissa, ret);
    int fractional_bits = 16;
    int fixed = float_to_fixed(exponent, mantissa, fractional_bits);
    printf("float_to_fixed(%d, %d, %d) = %d\n", exponent, mantissa,
           fractional_bits, fixed);
    mantissa = fixed_to_float(fractional_bits, fixed, &exponent);
    printf("fixed_to_float(%d, %d, %d) = %d\n", fractional_bits, fixed,
           exponent, mantissa);
    ret = show_float(buf, sizeof buf - 1, exponent, mantissa);
    printf("show_float(\"%s\", %d, %d, %d) = %d\n", buf, (int)sizeof buf - 1,
           exponent, mantissa, ret);
    fixed = read_fixed(arg, len, fractional_bits);
    printf("read_fixed(\"%s\", %d, %d) = %d\n", arg, len, fractional_bits,
           fixed);
    ret = show_fixed(buf, sizeof buf - 1, fractional_bits, fixed);
    printf("show_fixed(\"%s\", %d, %d, %d) = %d\n", buf, (int)sizeof buf - 1,
           fractional_bits, fixed, ret);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1080 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jl     130f <main+0x17f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
lea    -0x54(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1030 <read_float@plt>
mov    %eax,-0x68(%rbp)
mov    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
mov    -0x54(%rbp),%ecx
mov    -0x58(%rbp),%r8d
mov    -0x68(%rbp),%r9d
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x10,-0x6c(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
mov    -0x6c(%rbp),%edx
call   1040 <float_to_fixed@plt>
mov    %eax,-0x70(%rbp)
mov    -0x54(%rbp),%esi
mov    -0x58(%rbp),%edx
mov    -0x6c(%rbp),%ecx
mov    -0x70(%rbp),%r8d
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x6c(%rbp),%edi
mov    -0x70(%rbp),%esi
lea    -0x54(%rbp),%rdx
call   10b0 <fixed_to_float@plt>
mov    %eax,-0x58(%rbp)
mov    -0x6c(%rbp),%esi
mov    -0x70(%rbp),%edx
mov    -0x54(%rbp),%ecx
mov    -0x58(%rbp),%r8d
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    $0x3f,%esi
call   10a0 <show_float@plt>
mov    %eax,-0x68(%rbp)
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%ecx
mov    -0x58(%rbp),%r8d
mov    -0x68(%rbp),%r9d
lea    0xdc9(%rip),%rdi
mov    $0x3f,%edx
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
mov    -0x6c(%rbp),%edx
call   1090 <read_fixed@plt>
mov    %eax,-0x70(%rbp)
mov    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
mov    -0x6c(%rbp),%ecx
mov    -0x70(%rbp),%r8d
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x6c(%rbp),%edx
mov    -0x70(%rbp),%ecx
mov    $0x3f,%esi
call   1070 <show_fixed@plt>
mov    %eax,-0x68(%rbp)
lea    -0x50(%rbp),%rsi
mov    -0x6c(%rbp),%ecx
mov    -0x70(%rbp),%r8d
mov    -0x68(%rbp),%r9d
lea    0xda4(%rip),%rdi
mov    $0x3f,%edx
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
cmp    $0x2,%edi
jl     12f0 <main+0x170>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <read_float@plt>
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xe20(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    $0x10,%edx
call   1040 <float_to_fixed@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xe10(%rip),%rdi
mov    $0x10,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x10,%edi
mov    %ebp,%esi
mov    %r14,%rdx
call   10a0 <fixed_to_float@plt>
mov    %eax,0x8(%rsp)
mov    0xc(%rsp),%ecx
lea    0xe04(%rip),%rdi
mov    $0x10,%esi
mov    %ebp,%edx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x3f,%esi
call   1090 <show_float@plt>
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xdea(%rip),%rdi
mov    %r14,%rsi
mov    $0x3f,%edx
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    $0x10,%edx
call   1080 <read_fixed@plt>
mov    %eax,%ebp
lea    0xde2(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    $0x10,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x3f,%esi
mov    $0x10,%edx
mov    %ebp,%ecx
call   1070 <show_fixed@plt>
lea    0xdd1(%rip),%rdi
mov    %r14,%rsi
mov    $0x3f,%edx
mov    $0x10,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"read_float(\22%s\22, %d, %d, %d) = %d\0A\00"
@.str.1 = [33 x i8] c"float_to_fixed(%d, %d, %d) = %d\0A\00"
@.str.2 = [33 x i8] c"fixed_to_float(%d, %d, %d) = %d\0A\00"
@.str.3 = [35 x i8] c"show_float(\22%s\22, %d, %d, %d) = %d\0A\00"
@.str.4 = [31 x i8] c"read_fixed(\22%s\22, %d, %d) = %d\0A\00"
@.str.5 = [35 x i8] c"show_fixed(\22%s\22, %d, %d, %d) = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [64 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [64 x i8]* %6 to i8*
%15 = load i32, i32* %4
%16 = icmp sge i32 %15, 2
br i1 %16, label %17, label %76
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %10
%23 = load i8*, i8** %9
%24 = load i32, i32* %10
%25 = call i32 @read_float(i8* %23, i32 %24, i32* %7, i32* %8)
store i32 %25, i32* %11
%26 = load i8*, i8** %9
%27 = load i32, i32* %10
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = load i32, i32* %11
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %27, i32 %28, i32 %29, i32 %30)
store i32 16, i32* %12
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = load i32, i32* %12
%35 = call i32 @float_to_fixed(i32 %32, i32 %33, i32 %34)
store i32 %35, i32* %13
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = load i32, i32* %12
%39 = load i32, i32* %13
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %37, i32 %38, i32 %39)
%41 = load i32, i32* %12
%42 = load i32, i32* %13
%43 = call i32 @fixed_to_float(i32 %41, i32 %42, i32* %7)
store i32 %43, i32* %8
%44 = load i32, i32* %12
%45 = load i32, i32* %13
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %45, i32 %46, i32 %47)
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = call i32 @show_float(i8* %49, i32 63, i32 %50, i32 %51)
store i32 %52, i32* %11
%53 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = load i32, i32* %11
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %53, i32 63, i32 %54, i32 %55, i32 %56)
%58 = load i8*, i8** %9
%59 = load i32, i32* %10
%60 = load i32, i32* %12
%61 = call i32 @read_fixed(i8* %58, i32 %59, i32 %60)
store i32 %61, i32* %13
%62 = load i8*, i8** %9
%63 = load i32, i32* %10
%64 = load i32, i32* %12
%65 = load i32, i32* %13
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %62, i32 %63, i32 %64, i32 %65)
%67 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%68 = load i32, i32* %12
%69 = load i32, i32* %13
%70 = call i32 @show_fixed(i8* %67, i32 63, i32 %68, i32 %69)
store i32 %70, i32* %11
%71 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%72 = load i32, i32* %12
%73 = load i32, i32* %13
%74 = load i32, i32* %11
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %71, i32 63, i32 %72, i32 %73, i32 %74)
br label %76
76: ; preds = %17, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"read_float(\22%s\22, %d, %d, %d) = %d\0A\00"
@.str.1 = [33 x i8] c"float_to_fixed(%d, %d, %d) = %d\0A\00"
@.str.2 = [33 x i8] c"fixed_to_float(%d, %d, %d) = %d\0A\00"
@.str.3 = [35 x i8] c"show_float(\22%s\22, %d, %d, %d) = %d\0A\00"
@.str.4 = [31 x i8] c"read_fixed(\22%s\22, %d, %d) = %d\0A\00"
@.str.5 = [35 x i8] c"show_fixed(\22%s\22, %d, %d, %d) = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %37
8: ; preds = %2
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strlen(i8* %12)
%14 = call i32 @read_float(i8* %12, i32 %13, i32* %4, i32* %5)
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13, i32 %15, i32 %16, i32 %14)
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @float_to_fixed(i32 %18, i32 %19, i32 16)
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22, i32 16, i32 %20)
%24 = call i32 @fixed_to_float(i32 16, i32 %20, i32* %4)
store i32 %24, i32* %5
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 16, i32 %20, i32 %25, i32 %24)
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = call i32 @show_float(i8* %6, i32 63, i32 %27, i32 %28)
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 63, i32 %30, i32 %31, i32 %29)
%33 = call i32 @read_fixed(i8* %12, i32 %13, i32 16)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %12, i32 %13, i32 16, i32 %33)
%35 = call i32 @show_fixed(i8* %6, i32 63, i32 16, i32 %33)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %6, i32 63, i32 16, i32 %33, i32 %35)
br label %37
37: ; preds = %8, %2
ret i32 0
}