#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, int, int, int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ sscanf(char *, char *, double *, int *, int *, int *, int *);
scalar_t__ time(int /*<<< orphan*/ *);
int zipf(double, int);
int main(int argc, char *argv[]) {
  char line[80];
  char iotype;
  int io, no_dev;
  double io_ratio;
  char *dev, *trace_type;
  int logical_adrs, tmp;
  int size;
  double jiffies;
  FILE *input, *output;
  if ((input = fopen("input_trace.data", "r")) == NULL) {
    printf("fopen error\n");
    exit(-1);
  }
  if ((output = fopen("micro.trace", "wr")) == NULL) {
    printf("fopen error2\n");
    exit(-1);
  }
  srand((unsigned)time(NULL));
  while (fgets(line, 80, input) != NULL) {
    sscanf(line, "%lf\t%d\t%9d\t%d\t%d\n", &jiffies, &no_dev, &logical_adrs,
           &size, &io);
    io_ratio = rand() % 100;
    if ((double)(2 / (double)(3 + 2)) * 100 < io_ratio) {
      io = 1;
    } else {
      io = 0;
    }
    logical_adrs = zipf(0.8, 10000000);
    fprintf(output, "%lf\t0\t%9d\t%d\t%d\n", jiffies, logical_adrs, size, io);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe74(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmp    $0x0,%rax
jne    11f3 <main+0x53>
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    0xe34(%rip),%rdi
lea    0xe39(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0xb0(%rbp)
cmp    $0x0,%rax
jne    122d <main+0x8d>
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    -0x60(%rbp),%rdi
mov    -0xa8(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1317 <main+0x177>
lea    -0x60(%rbp),%rdi
lea    0xde4(%rip),%rsi
lea    -0xa0(%rbp),%rdx
lea    -0x6c(%rbp),%rcx
lea    -0x8c(%rbp),%r8
lea    -0x94(%rbp),%r9
lea    -0x68(%rbp),%rax
mov    %rax,(%rsp)
call   1090 <sscanf@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
cvtsi2sd %edx,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  0xd4e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12c8 <main+0x128>
movl   $0x1,-0x68(%rbp)
jmp    12cf <main+0x12f>
movl   $0x0,-0x68(%rbp)
movsd  0xd31(%rip),%xmm0
mov    $0x989680,%edi
call   1040 <zipf@plt>
mov    %eax,-0x8c(%rbp)
mov    -0xb0(%rbp),%rdi
movsd  -0xa0(%rbp),%xmm0
ff
mov    -0x8c(%rbp),%edx
mov    -0x94(%rbp),%ecx
mov    -0x68(%rbp),%r8d
lea    0xd50(%rip),%rsi
call   1070 <fprintf@plt>
jmp    123d <main+0x9d>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xe50(%rip),%rdi
lea    0xea3(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12e5 <main+0x145>
mov    %rax,%r14
lea    0xe42(%rip),%rdi
lea    0xe47(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12ee <main+0x14e>
mov    %rax,%r12
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0x30(%rsp),%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12d1 <main+0x131>
lea    0x30(%rsp),%rbx
lea    0x1c(%rsp),%r15
lea    0x18(%rsp),%r13
lea    0xe0c(%rip),%rbp
xchg   %ax,%ax
lea    0x14(%rsp),%rax
mov    %rax,(%rsp)
mov    %rbx,%rdi
lea    0xde5(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0x2c(%rsp),%rcx
mov    %r15,%r8
mov    %r13,%r9
call   1090 <sscanf@plt>
xor    %eax,%eax
call   10c0 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
xor    %ecx,%ecx
cmp    $0x29,%eax
setge  %cl
mov    %ecx,0x14(%rsp)
movsd  0xd72(%rip),%xmm0
mov    $0x989680,%edi
call   1040 <zipf@plt>
mov    %eax,0x1c(%rsp)
movsd  0x20(%rsp),%xmm0
mov    0x18(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1230 <main+0x90>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd6c(%rip),%rdi
jmp    12f5 <main+0x155>
lea    0xd56(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"input_trace.data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen error\0A\00"
@.str.3 = [12 x i8] c"micro.trace\00"
@.str.4 = [3 x i8] c"wr\00"
@.str.5 = [14 x i8] c"fopen error2\0A\00"
@.str.6 = [18 x i8] c"%lf\09%d\09%9d\09%d\09%d\0A\00"
@.str.7 = [17 x i8] c"%lf\090\09%9d\09%d\09%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca i32*
%18 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %17
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %2
%25 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %25, i32** %18
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %24
%31 = call i64 @time(i32* null)
%32 = trunc i64 %31 to i32
%33 = call i32 @srand(i32 %32)
br label %34
34: ; preds = %49, %30
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%36 = load i32*, i32** %17
%37 = call i32* @fgets(i8* %35, i32 80, i32* %36)
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %57
39: ; preds = %34
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%41 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), double* %16, i32* %9, i32* %13, i32* %15, i32* %8)
%42 = call i32 (...) @rand()
%43 = srem i32 %42, 100
%44 = sitofp i32 %43 to double
store double %44, double* %10
%45 = load double, double* %10
%46 = fcmp olt double 4.000000e+01, %45
br i1 %46, label %47, label %48
47: ; preds = %39
store i32 1, i32* %8
br label %49
48: ; preds = %39
store i32 0, i32* %8
br label %49
49: ; preds = %48, %47
%50 = call i32 @zipf(double 8.000000e-01, i32 10000000)
store i32 %50, i32* %13
%51 = load i32*, i32** %18
%52 = load double, double* %16
%53 = load i32, i32* %13
%54 = load i32, i32* %15
%55 = load i32, i32* %8
%56 = call i32 @fprintf(i32* %51, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), double %52, i32 %53, i32 %54, i32 %55)
br label %34
57: ; preds = %34
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"input_trace.data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [12 x i8] c"micro.trace\00"
@.str.4 = [3 x i8] c"wr\00"
@.str.6 = [18 x i8] c"%lf\09%d\09%9d\09%d\09%d\0A\00"
@.str.7 = [17 x i8] c"%lf\090\09%9d\09%d\09%d\0A\00"
@str = [13 x i8] c"fopen error2\00"
@str.8 = [12 x i8] c"fopen error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast double* %8 to i8*
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 -1)
unreachable
26: ; preds = %20
%27 = tail call i64 @time(i32* null)
%28 = trunc i64 %27 to i32
%29 = tail call i32 @srand(i32 %28)
%30 = call i32* @fgets(i8* %9, i32 80, i32* %15)
%31 = icmp eq i32* %30, null
br i1 %31, label %45, label %32
32: ; preds = %26, %32
%33 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), double* %8, i32* %5, i32* %6, i32* %7, i32* %4)
%34 = call i32 (...) @rand()
%35 = srem i32 %34, 100
%36 = icmp sgt i32 %35, 40
%37 = zext i1 %36 to i32
store i32 %37, i32* %4
%38 = call i32 @zipf(double 8.000000e-01, i32 10000000)
store i32 %38, i32* %6
%39 = load double, double* %8
%40 = load i32, i32* %7
%41 = load i32, i32* %4
%42 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), double %39, i32 %38, i32 %40, i32 %41)
%43 = call i32* @fgets(i8* %9, i32 80, i32* %15)
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %32
45: ; preds = %32, %26
ret i32 0
}