#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 */
struct stat {
  int dummy;
};
struct progress_bar {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ progress_bar_update(struct progress_bar *, float,
                                       int /*<<< orphan*/);
int stat(char *, struct stat *);
int /*<<< orphan*/ *stderr;
int system(char *);
int /*<<< orphan*/ usleep(int);
void draw_progress(float percentage, int write_fp_event,
                   struct progress_bar *pb) {
  if (pb) {
    progress_bar_update(pb, percentage, 0);
  } else {
    fprintf(stderr, "\r%2.3f%%    ", percentage * 100);
    if (write_fp_event) {
      char *fileName = "/tmp/flashplayer.event";
      struct stat buf;
      int i = stat(fileName, &buf);
      int ret = 0;
      FILE *fp = NULL;
      if (100 == (percentage * 100)) {
        while (0 == stat(fileName, &buf)) {
          usleep(100);
        }
        if (fp = fopen(fileName, "w")) {
          fprintf(fp, "<event type=\"Progress\" value=\"progress\" "
                      "comment=\"100\"/>\n");
          fclose(fp);
          ret = system("/usr/bin/chumbyflashplayer.x -F1 >/dev/null 2>&1 &");
          usleep(1000);
        }
      } else if (0 != i) {
        if (fp = fopen(fileName, "w")) {
          fprintf(fp,
                  "<event type=\"Progress\" value=\"progress\" "
                  "comment=\"%2.3f\"/>\n",
                  percentage * 100);
          fclose(fp);
          ret = system("/usr/bin/chumbyflashplayer.x -F1 >/dev/null 2>&1 &");
        }
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<draw_progress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a4 <draw_progress+0x34>
mov    -0x10(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
xor    %esi,%esi
call   1070 <progress_bar_update@plt>
jmp    1321 <draw_progress+0x1b1>
mov    0x2e35(%rip),%rax
mov    (%rax),%rdi
movss  0xe4a(%rip),%xmm0
mulss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe3e(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x8(%rbp)
je     131c <draw_progress+0x1ac>
lea    0xe33(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movss  0xdf7(%rip),%xmm1
mulss  -0x4(%rbp),%xmm1
movss  0xdea(%rip),%xmm0
ucomiss %xmm1,%xmm0
jne    12a9 <draw_progress+0x139>
jp     12a9 <draw_progress+0x139>
jmp    122a <draw_progress+0xba>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1252 <draw_progress+0xe2>
mov    $0x64,%edi
call   1090 <usleep@plt>
jmp    122a <draw_progress+0xba>
mov    -0x18(%rbp),%rdi
lea    0xdcb(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12a4 <draw_progress+0x134>
mov    -0x30(%rbp),%rdi
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdd1(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x28(%rbp)
mov    $0x3e8,%edi
call   1090 <usleep@plt>
jmp    1317 <draw_progress+0x1a7>
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
je     1312 <draw_progress+0x1a2>
mov    -0x18(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     130d <draw_progress+0x19d>
mov    -0x30(%rbp),%rdi
movss  0xd22(%rip),%xmm0
mulss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xda8(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd5e(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x28(%rbp)
jmp    1312 <draw_progress+0x1a2>
jmp    1317 <draw_progress+0x1a7>
jmp    131c <draw_progress+0x1ac>
jmp    1321 <draw_progress+0x1b1>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_progress>:
test   %rsi,%rsi
je     118f <draw_progress+0xf>
mov    %rsi,%rdi
xor    %esi,%esi
jmp    1070 <progress_bar_update@plt>
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    0x2e41(%rip),%rax
mov    (%rax),%rdi
mulss  0xe56(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
cvtss2sd %xmm0,%xmm0
lea    0xe49(%rip),%rsi
movsd  %xmm0,0x10(%rsp)
mov    $0x1,%al
call   1050 <fprintf@plt>
test   %ebx,%ebx
je     12db <draw_progress+0x15b>
lea    0xe3a(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
movss  0xc(%rsp),%xmm0
ucomiss 0xe12(%rip),%xmm0
jne    1291 <draw_progress+0x111>
jp     1291 <draw_progress+0x111>
lea    0xe10(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %eax,%eax
jne    1239 <draw_progress+0xb9>
lea    0xdfb(%rip),%r14
lea    0x8(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x64,%edi
call   10a0 <usleep@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <stat@plt>
test   %eax,%eax
je     1220 <draw_progress+0xa0>
lea    0xdd1(%rip),%rdi
lea    0xde1(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12db <draw_progress+0x15b>
mov    %rax,%rbx
lea    0xdcb(%rip),%rdi
mov    $0x38,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xde3(%rip),%rdi
call   1040 <system@plt>
mov    $0x3e8,%edi
call   10a0 <usleep@plt>
jmp    12db <draw_progress+0x15b>
test   %eax,%eax
je     12db <draw_progress+0x15b>
lea    0xd75(%rip),%rdi
lea    0xd85(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12db <draw_progress+0x15b>
mov    %rax,%rbx
lea    0xddf(%rip),%rsi
mov    %rax,%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd8d(%rip),%rdi
call   1040 <system@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.progress_bar = type { i32 }
%struct.stat = type { i32 }
@stderr = global i32* null
@.str = [13 x i8] c"\0D%2.3f%% \00"
@.str.1 = [23 x i8] c"/tmp/flashplayer.event\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [57 x i8] c"<event type=\22Progress\22 value=\22progress\22 comment=\22100\22/>\0A\00"
@.str.4 = [51 x i8] c"/usr/bin/chumbyflashplayer.x -F1 >/dev/null 2>&1 &\00"
@.str.5 = [59 x i8] c"<event type=\22Progress\22 value=\22progress\22 comment=\22%2.3f\22/>\0A\00"
define void @draw_progress(float %0, i32 %1, %struct.progress_bar* %2) {
%4 = alloca float
%5 = alloca i32
%6 = alloca %struct.progress_bar*
%7 = alloca i8*
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store float %0, float* %4
store i32 %1, i32* %5
store %struct.progress_bar* %2, %struct.progress_bar** %6
%12 = load %struct.progress_bar*, %struct.progress_bar** %6
%13 = icmp ne %struct.progress_bar* %12, null
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load %struct.progress_bar*, %struct.progress_bar** %6
%16 = load float, float* %4
%17 = call i32 @progress_bar_update(%struct.progress_bar* %15, float %16, i32 0)
br label %71
18: ; preds = %3
%19 = load i32*, i32** @stderr
%20 = load float, float* %4
%21 = fmul float %20, 1.000000e+02
%22 = fpext float %21 to double
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %22)
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %70
26: ; preds = %18
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8** %7
%27 = load i8*, i8** %7
%28 = call i32 @stat(i8* %27, %struct.stat* %8)
store i32 %28, i32* %9
store i32 0, i32* %10
store i32* null, i32** %11
%29 = load float, float* %4
%30 = fmul float %29, 1.000000e+02
%31 = fcmp oeq float 1.000000e+02, %30
br i1 %31, label %32, label %51
32: ; preds = %26
br label %33
33: ; preds = %37, %32
%34 = load i8*, i8** %7
%35 = call i32 @stat(i8* %34, %struct.stat* %8)
%36 = icmp eq i32 0, %35
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @usleep(i32 100)
br label %33
39: ; preds = %33
%40 = load i8*, i8** %7
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %41, i32** %11
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i32*, i32** %11
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32*, i32** %11
%47 = call i32 @fclose(i32* %46)
%48 = call i32 @system(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
store i32 %48, i32* %10
%49 = call i32 @usleep(i32 1000)
br label %50
50: ; preds = %43, %39
br label %69
51: ; preds = %26
%52 = load i32, i32* %9
%53 = icmp ne i32 0, %52
br i1 %53, label %54, label %68
54: ; preds = %51
%55 = load i8*, i8** %7
%56 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %56, i32** %11
%57 = icmp ne i32* %56, null
br i1 %57, label %58, label %67
58: ; preds = %54
%59 = load i32*, i32** %11
%60 = load float, float* %4
%61 = fmul float %60, 1.000000e+02
%62 = fpext float %61 to double
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0), double %62)
%64 = load i32*, i32** %11
%65 = call i32 @fclose(i32* %64)
%66 = call i32 @system(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
store i32 %66, i32* %10
br label %67
67: ; preds = %58, %54
br label %68
68: ; preds = %67, %51
br label %69
69: ; preds = %68, %50
br label %70
70: ; preds = %69, %18
br label %71
71: ; preds = %70, %14
ret void
}

LLVM IR (-O2):
%struct.progress_bar = type { i32 }
%struct.stat = type { i32 }
@stderr = global i32* null
@.str = [13 x i8] c"\0D%2.3f%% \00"
@.str.1 = [23 x i8] c"/tmp/flashplayer.event\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [57 x i8] c"<event type=\22Progress\22 value=\22progress\22 comment=\22100\22/>\0A\00"
@.str.4 = [51 x i8] c"/usr/bin/chumbyflashplayer.x -F1 >/dev/null 2>&1 &\00"
@.str.5 = [59 x i8] c"<event type=\22Progress\22 value=\22progress\22 comment=\22%2.3f\22/>\0A\00"
define void @draw_progress(float %0, i32 %1, %struct.progress_bar* %2) {
%4 = alloca %struct.stat
%5 = icmp eq %struct.progress_bar* %2, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @progress_bar_update(%struct.progress_bar* %2, float %0, i32 0)
br label %43
8: ; preds = %3
%9 = load i32*, i32** @stderr
%10 = fmul float %0, 1.000000e+02
%11 = fpext float %10 to double
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %11)
%13 = icmp eq i32 %1, 0
br i1 %13, label %43, label %14
14: ; preds = %8
%15 = bitcast %struct.stat* %4 to i8*
%16 = call i32 @stat(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %4)
%17 = fcmp oeq float %10, 1.000000e+02
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = call i32 @stat(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18, %21
%22 = tail call i32 @usleep(i32 100)
%23 = call i32 @stat(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %4)
%24 = icmp eq i32 %23, 0
br i1 %24, label %21, label %25
25: ; preds = %21, %18
%26 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %42, label %28
28: ; preds = %25
%29 = tail call i64 @fwrite(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i64 56, i64 1, i32* %26)
%30 = tail call i32 @fclose(i32* %26)
%31 = tail call i32 @system(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%32 = tail call i32 @usleep(i32 1000)
br label %42
33: ; preds = %14
%34 = icmp eq i32 %16, 0
br i1 %34, label %42, label %35
35: ; preds = %33
%36 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0), double %11)
%40 = tail call i32 @fclose(i32* %36)
%41 = tail call i32 @system(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %33, %38, %35, %25, %28
br label %43
43: ; preds = %8, %42, %6
ret void
}