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

/* Variables and functions */
double atof(char *);
int checkStringIsNumber(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ printf(char *, ...);
int readSplit(int /*<<< orphan*/ *, char *, char, int);
int main(int argc, char *argv[]) {
  int numvalid, res;
  double num, n;
  FILE *rfile, *wfile;
  char buff[100] = {0};
  if (argc != 4) {
    printf("Usage: ./program infile outfile num\n");
    return 0;
  }
  numvalid = checkStringIsNumber(argv[3]);
  if (numvalid == -1) {
    printf("Invalid number %s\n", argv[3]);
    return -1;
  }
  num = atof(argv[3]);
  rfile = fopen(argv[1], "r");
  if (rfile == NULL) {
    printf("Invalid input file %s\n", argv[1]);
    return -1;
  }
  wfile = fopen(argv[2], "w");
  if (wfile == NULL) {
    printf("Invalid output file %s\n", argv[2]);
    fclose(rfile);
    return -1;
  }
  res = 0;
  while (res != -1) {
    res = readSplit(rfile, buff, ' ', 100);
    numvalid = checkStringIsNumber(buff);
    if (numvalid == -1) {
      printf("Invalid number in input file %s\n", argv[1]);
      fclose(rfile);
      fclose(wfile);
      return 0;
    }
    n = atof(buff);
    if (fprintf(wfile, "%f ", n * num) < 0) {
      printf("Could not write to file %s\n", argv[2]);
      fclose(rfile);
      fclose(wfile);
    }
  }
  fclose(rfile);
  fclose(wfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
cmpl   $0x4,-0x8(%rbp)
je     11d0 <main+0x50>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a7 <main+0x227>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <checkStringIsNumber@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    120c <main+0x8c>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a7 <main+0x227>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1263 <main+0xe3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a7 <main+0x227>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xddf(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12b1 <main+0x131>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a7 <main+0x227>
movl   $0x0,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     138e <main+0x20e>
mov    -0x30(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    $0x20,%edx
mov    $0x64,%ecx
call   1070 <readSplit@plt>
mov    %eax,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
call   1090 <checkStringIsNumber@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    132c <main+0x1ac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a7 <main+0x227>
lea    -0xa0(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
lea    0xd3a(%rip),%rsi
call   1080 <fprintf@plt>
cmp    $0x0,%rax
jge    1389 <main+0x209>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12b8 <main+0x138>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
xorpd  %xmm0,%xmm0
movapd %xmm0,0x60(%rsp)
movapd %xmm0,0x50(%rsp)
movapd %xmm0,0x40(%rsp)
movapd %xmm0,0x30(%rsp)
movapd %xmm0,0x20(%rsp)
movapd %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
cmp    $0x4,%edi
jne    12b3 <main+0x133>
mov    %rsi,%r14
mov    0x18(%rsi),%rdi
call   1090 <checkStringIsNumber@plt>
mov    0x18(%r14),%rsi
cmp    $0xffffffff,%eax
je     12c3 <main+0x143>
mov    %rsi,%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x8(%r14),%rdi
lea    0xe1a(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12cc <main+0x14c>
mov    %rax,%r15
mov    0x10(%r14),%rdi
lea    0xe17(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12f4 <main+0x174>
mov    %rax,%r12
lea    0x10(%rsp),%rbx
lea    0xe35(%rip),%r13
jmp    1249 <main+0xc9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0xffffffff,%ebp
je     1310 <main+0x190>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
mov    $0x64,%ecx
call   1070 <readSplit@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <checkStringIsNumber@plt>
cmp    $0xffffffff,%eax
je     1322 <main+0x1a2>
mov    %rbx,%rdi
call   1040 <atof@plt>
mulsd  0x8(%rsp),%xmm0
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <fprintf@plt>
test   %rax,%rax
jns    1240 <main+0xc0>
mov    0x10(%r14),%rsi
lea    0xdd1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    1240 <main+0xc0>
lea    0xdcd(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    12e3 <main+0x163>
lea    0xd36(%rip),%rdi
jmp    12d7 <main+0x157>
mov    0x8(%r14),%rsi
lea    0xd3e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%r14),%rsi
lea    0xd2f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    12de <main+0x15e>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    12bf <main+0x13f>
mov    0x8(%r14),%rsi
lea    0xd19(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    12e3 <main+0x163>

LLVM IR (-O0):
@.str = [37 x i8] c"Usage: ./program infile outfile num\0A\00"
@.str.1 = [19 x i8] c"Invalid number %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"Invalid input file %s\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [24 x i8] c"Invalid output file %s\0A\00"
@.str.6 = [33 x i8] c"Invalid number in input file %s\0A\00"
@.str.7 = [4 x i8] c"%f \00"
@.str.8 = [28 x i8] c"Could not write to file %s\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 double
%9 = alloca double
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [100 x i8]* %12 to i8*
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %105
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 3
%21 = load i8*, i8** %20
%22 = call i32 @checkStringIsNumber(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 -1, i32* %3
br label %105
30: ; preds = %18
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call double @atof(i8* %33)
store double %34, double* %8
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %10
%39 = load i32*, i32** %10
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %46
41: ; preds = %30
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %44)
store i32 -1, i32* %3
br label %105
46: ; preds = %30
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %50, i32** %11
%51 = load i32*, i32** %11
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %60
53: ; preds = %46
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = load i32*, i32** %10
%59 = call i32 @fclose(i32* %58)
store i32 -1, i32* %3
br label %105
60: ; preds = %46
store i32 0, i32* %7
br label %61
61: ; preds = %99, %60
%62 = load i32, i32* %7
%63 = icmp ne i32 %62, -1
br i1 %63, label %64, label %100
64: ; preds = %61
%65 = load i32*, i32** %10
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%67 = call i32 @readSplit(i32* %65, i8* %66, i8 signext 32, i32 100)
store i32 %67, i32* %7
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%69 = call i32 @checkStringIsNumber(i8* %68)
store i32 %69, i32* %6
%70 = load i32, i32* %6
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %81
72: ; preds = %64
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 1
%75 = load i8*, i8** %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %75)
%77 = load i32*, i32** %10
%78 = call i32 @fclose(i32* %77)
%79 = load i32*, i32** %11
%80 = call i32 @fclose(i32* %79)
store i32 0, i32* %3
br label %105
81: ; preds = %64
%82 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%83 = call double @atof(i8* %82)
store double %83, double* %9
%84 = load i32*, i32** %11
%85 = load double, double* %9
%86 = load double, double* %8
%87 = fmul double %85, %86
%88 = call i64 @fprintf(i32* %84, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), double %87)
%89 = icmp slt i64 %88, 0
br i1 %89, label %90, label %99
90: ; preds = %81
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 2
%93 = load i8*, i8** %92
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %93)
%95 = load i32*, i32** %10
%96 = call i32 @fclose(i32* %95)
%97 = load i32*, i32** %11
%98 = call i32 @fclose(i32* %97)
br label %99
99: ; preds = %90, %81
br label %61
100: ; preds = %61
%101 = load i32*, i32** %10
%102 = call i32 @fclose(i32* %101)
%103 = load i32*, i32** %11
%104 = call i32 @fclose(i32* %103)
store i32 0, i32* %3
br label %105
105: ; preds = %100, %72, %53, %41, %25, %16
%106 = load i32, i32* %3
ret i32 %106
}

LLVM IR (-O2):
@.str.1 = [19 x i8] c"Invalid number %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"Invalid input file %s\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [24 x i8] c"Invalid output file %s\0A\00"
@.str.6 = [33 x i8] c"Invalid number in input file %s\0A\00"
@.str.7 = [4 x i8] c"%f \00"
@.str.8 = [28 x i8] c"Could not write to file %s\0A\00"
@str = [36 x i8] c"Usage: ./program infile outfile num\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %58
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = tail call i32 @checkStringIsNumber(i8* %10)
%12 = icmp eq i32 %11, -1
%13 = load i8*, i8** %9
br i1 %12, label %14, label %16
14: ; preds = %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %58
16: ; preds = %8
%17 = tail call double @atof(i8* %13)
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %18
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %58
25: ; preds = %16
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = tail call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i8*, i8** %26
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %31)
%33 = tail call i32 @fclose(i32* %20)
br label %58
34: ; preds = %25, %53
%35 = call i32 @readSplit(i32* %20, i8* %4, i8 signext 32, i32 100)
%36 = call i32 @checkStringIsNumber(i8* %4)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8*, i8** %18
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %39)
%41 = call i32 @fclose(i32* %20)
%42 = call i32 @fclose(i32* %28)
br label %58
43: ; preds = %34
%44 = call double @atof(i8* %4)
%45 = fmul double %17, %44
%46 = call i64 @fprintf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), double %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %43
%49 = load i8*, i8** %26
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %49)
%51 = call i32 @fclose(i32* %20)
%52 = call i32 @fclose(i32* %28)
br label %53
53: ; preds = %48, %43
%54 = icmp eq i32 %35, -1
br i1 %54, label %55, label %34
55: ; preds = %53
%56 = call i32 @fclose(i32* %20)
%57 = call i32 @fclose(i32* %28)
br label %58
58: ; preds = %55, %38, %30, %22, %14, %6
%59 = phi i32 [ 0, %6 ], [ -1, %14 ], [ -1, %22 ], [ -1, %30 ], [ 0, %38 ], [ 0, %55 ]
ret i32 %59
}