#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 timeval {
  double tv_sec;
  double tv_usec;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sleep(int);
int system(char *);
int measure_umount_time(void) {
  int system_return;
  struct timeval start_timer;
  struct timeval stop_timer;
  double time_elapsed = 0;
  system_return = system("mount -t vfat /dev/sdc1 /mnt/flash");
  if (system_return == -1) {
    perror("system");
    return EXIT_FAILURE;
  }
  sleep(10);
  gettimeofday(&start_timer, NULL);
  system_return = system("umount /mnt/flash");
  gettimeofday(&stop_timer, NULL);
  if (system_return != -1) {
    time_elapsed = (stop_timer.tv_sec - start_timer.tv_sec) * 1000.0;
    time_elapsed += (stop_timer.tv_usec - start_timer.tv_usec) / 1000.0;
    printf("\numount : %f ms\n", time_elapsed);
  } else {
    perror("system");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<measure_umount_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xea1(%rip),%rdi
call   1030 <system@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1196 <measure_umount_time+0x46>
lea    0xeab(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124d <measure_umount_time+0xfd>
mov    $0xa,%edi
call   1070 <sleep@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    0xe7e(%rip),%rdi
call   1030 <system@plt>
mov    %eax,-0x8(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmpl   $0xffffffff,-0x8(%rbp)
je     1224 <measure_umount_time+0xd4>
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xe00(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
jmp    1241 <measure_umount_time+0xf1>
lea    0xe00(%rip),%rdi
call   1060 <perror@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124d <measure_umount_time+0xfd>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<measure_umount_time>:
push   %rbx
sub    $0x20,%rsp
lea    0xeac(%rip),%rdi
call   1030 <system@plt>
cmp    $0xffffffff,%eax
je     11df <measure_umount_time+0x8f>
mov    $0xa,%edi
call   1070 <sleep@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0xeaf(%rip),%rdi
call   1030 <system@plt>
mov    %eax,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
cmp    $0xffffffff,%ebx
je     11df <measure_umount_time+0x8f>
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm1
movsd  0xe4e(%rip),%xmm2
mulsd  %xmm2,%xmm1
subsd  0x18(%rsp),%xmm0
divsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe45(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dee(%rip),%rax
jmp    11d7 <measure_umount_time+0x87>

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [35 x i8] c"mount -t vfat /dev/sdc1 /mnt/flash\00"
@.str.1 = [7 x i8] c"system\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [18 x i8] c"umount /mnt/flash\00"
@.str.3 = [17 x i8] c"\0Aumount : %f ms\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @measure_umount_time() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca double
store double 0.000000e+00, double* %5
%6 = call i32 @system(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
store i32 %11, i32* %1
br label %41
12: ; preds = %0
%13 = call i32 @sleep(i32 10)
%14 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%15 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 %15, i32* %2
%16 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %36
19: ; preds = %12
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%21 = load double, double* %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%23 = load double, double* %22
%24 = fsub double %21, %23
%25 = fmul double %24, 1.000000e+03
store double %25, double* %5
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%27 = load double, double* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%29 = load double, double* %28
%30 = fsub double %27, %29
%31 = fdiv double %30, 1.000000e+03
%32 = load double, double* %5
%33 = fadd double %32, %31
store double %33, double* %5
%34 = load double, double* %5
%35 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), double %34)
br label %39
36: ; preds = %12
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %1
br label %41
39: ; preds = %19
%40 = load i32, i32* @EXIT_SUCCESS
store i32 %40, i32* %1
br label %41
41: ; preds = %39, %36, %9
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [35 x i8] c"mount -t vfat /dev/sdc1 /mnt/flash\00"
@.str.1 = [7 x i8] c"system\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [18 x i8] c"umount /mnt/flash\00"
@.str.3 = [17 x i8] c"\0Aumount : %f ms\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @measure_umount_time() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = tail call i32 @system(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %32
9: ; preds = %0
%10 = tail call i32 @sleep(i32 10)
%11 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%12 = tail call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%14 = icmp eq i32 %12, -1
br i1 %14, label %30, label %15
15: ; preds = %9
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%17 = load double, double* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%19 = load double, double* %18
%20 = fsub double %17, %19
%21 = fmul double %20, 1.000000e+03
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%23 = load double, double* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%25 = load double, double* %24
%26 = fsub double %23, %25
%27 = fdiv double %26, 1.000000e+03
%28 = fadd double %21, %27
%29 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), double %28)
br label %32
30: ; preds = %9
%31 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %15, %30, %7
%33 = phi i32* [ @EXIT_FAILURE, %7 ], [ @EXIT_SUCCESS, %15 ], [ @EXIT_FAILURE, %30 ]
%34 = load i32, i32* %33
ret i32 %34
}