#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 {
  long long tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int atoi(scalar_t__);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long long, ...);
scalar_t__ getenv(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ sesc_tvsub(struct timeval *, struct timeval *,
                              struct timeval *);
int /*<<< orphan*/ stderr;
void sesc_simulation_mark() {
  static int mark = 0;
  static int mark1 = 0;
  static int mark2 = 0;
  static struct timeval tv1;
  if (mark == 0) {
    gettimeofday(&tv1, 0);
    if (getenv("SESC_1"))
      mark1 = atoi(getenv("SESC_1"));
    if (getenv("SESC_2"))
      mark2 = atoi(getenv("SESC_2"));
    else
      mark2 = -1;
  }
  if (mark == mark1) {
    gettimeofday(&tv1, 0);
  }
  fprintf(stderr, "sesc_simulation_mark %d (native) (sim from %d to %d mark)\n",
          mark, mark1, mark2);
  if (mark == mark2) {
    struct timeval tv2;
    gettimeofday(&tv2, 0);
    struct timeval td;
    long long usecs;
    sesc_tvsub(&td, &tv2, &tv1);
    usecs = td.tv_sec;
    usecs *= 1000000;
    usecs += td.tv_usec;
    fprintf(stderr, "sesc_simulation_mark FINISH %lld usesc\n", usecs);
    exit(0);
  }
  mark++;
}


x86 assembly (clang, -O0):
<sesc_simulation_mark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
cmpl   $0x0,0x2ee9(%rip)
jne    11f7 <sesc_simulation_mark+0x97>
lea    0x2eec(%rip),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11b3 <sesc_simulation_mark+0x53>
lea    0xe60(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,0x2ea9(%rip)
lea    0xe4d(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11e8 <sesc_simulation_mark+0x88>
lea    0xe37(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,0x2e7d(%rip)
jmp    11f2 <sesc_simulation_mark+0x92>
movl   $0xffffffff,0x2e6e(%rip)
ff ff ff
jmp    11f7 <sesc_simulation_mark+0x97>
mov    0x2e5b(%rip),%eax
cmp    0x2e59(%rip),%eax
jne    1217 <sesc_simulation_mark+0xb7>
lea    0x2e58(%rip),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
movslq 0x2e31(%rip),%rdx
mov    0x2e2f(%rip),%ecx
mov    0x2e2c(%rip),%r8d
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e10(%rip),%eax
cmp    0x2e12(%rip),%eax
jne    12b5 <sesc_simulation_mark+0x155>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    0x2dfa(%rip),%rdx
call   1040 <sesc_tvsub@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
imul   $0xf4240,-0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2d9d(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2d94(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sesc_simulation_mark>:
push   %r14
push   %rbx
sub    $0x28,%rsp
cmpl   $0x0,0x2eea(%rip)
jne    11c3 <sesc_simulation_mark+0x63>
lea    0x2ef1(%rip),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0xe7b(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     119d <sesc_simulation_mark+0x3d>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,0x2ebf(%rip)
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b8 <sesc_simulation_mark+0x58>
mov    %rax,%rdi
call   1070 <atoi@plt>
jmp    11bd <sesc_simulation_mark+0x5d>
mov    $0xffffffff,%eax
mov    %eax,0x2e9d(%rip)
mov    0x2e8f(%rip),%eax
mov    0x2e8d(%rip),%ecx
cmp    %ecx,%eax
jne    11ed <sesc_simulation_mark+0x8d>
lea    0x2e8e(%rip),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x2e71(%rip),%eax
mov    0x2e6f(%rip),%ecx
mov    0x2dec(%rip),%rbx
mov    (%rbx),%edi
movslq %eax,%rdx
mov    0x2e60(%rip),%r8d
lea    0xe07(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2e44(%rip),%eax
cmp    0x2e46(%rip),%eax
je     122d <sesc_simulation_mark+0xcd>
add    $0x1,%eax
mov    %eax,0x2e33(%rip)
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0x2e25(%rip),%rdx
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1040 <sesc_tvsub@plt>
imul   $0xf4240,0x8(%rsp),%rdx
add    0x10(%rsp),%rdx
mov    (%rbx),%edi
lea    0xde2(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@sesc_simulation_mark.mark = internal global i32 0
@sesc_simulation_mark.mark1 = internal global i32 0
@sesc_simulation_mark.mark2 = internal global i32 0
@sesc_simulation_mark.tv1 = internal global %struct.timeval zeroinitializer
@.str = [7 x i8] c"SESC_1\00"
@.str.1 = [7 x i8] c"SESC_2\00"
@stderr = global i32 0
@.str.2 = [59 x i8] c"sesc_simulation_mark %d (native) (sim from %d to %d mark)\0A\00"
@.str.3 = [40 x i8] c"sesc_simulation_mark FINISH %lld usesc\0A\00"
define void @sesc_simulation_mark() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca i64
%4 = load i32, i32* @sesc_simulation_mark.mark
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %0
%7 = call i32 @gettimeofday(%struct.timeval* @sesc_simulation_mark.tv1, i32 0)
%8 = call i64 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = call i64 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @atoi(i64 %11)
store i32 %12, i32* @sesc_simulation_mark.mark1
br label %13
13: ; preds = %10, %6
%14 = call i64 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i64 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @atoi(i64 %17)
store i32 %18, i32* @sesc_simulation_mark.mark2
br label %20
19: ; preds = %13
store i32 -1, i32* @sesc_simulation_mark.mark2
br label %20
20: ; preds = %19, %16
br label %21
21: ; preds = %20, %0
%22 = load i32, i32* @sesc_simulation_mark.mark
%23 = load i32, i32* @sesc_simulation_mark.mark1
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @gettimeofday(%struct.timeval* @sesc_simulation_mark.tv1, i32 0)
br label %27
27: ; preds = %25, %21
%28 = load i32, i32* @stderr
%29 = load i32, i32* @sesc_simulation_mark.mark
%30 = sext i32 %29 to i64
%31 = load i32, i32* @sesc_simulation_mark.mark1
%32 = load i32, i32* @sesc_simulation_mark.mark2
%33 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i64 %30, i32 %31, i32 %32)
%34 = load i32, i32* @sesc_simulation_mark.mark
%35 = load i32, i32* @sesc_simulation_mark.mark2
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %52
37: ; preds = %27
%38 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%39 = call i32 @sesc_tvsub(%struct.timeval* %2, %struct.timeval* %1, %struct.timeval* @sesc_simulation_mark.tv1)
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%41 = load i64, i64* %40
store i64 %41, i64* %3
%42 = load i64, i64* %3
%43 = mul nsw i64 %42, 1000000
store i64 %43, i64* %3
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%45 = load i64, i64* %44
%46 = load i64, i64* %3
%47 = add nsw i64 %46, %45
store i64 %47, i64* %3
%48 = load i32, i32* @stderr
%49 = load i64, i64* %3
%50 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 %49)
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %27
%53 = load i32, i32* @sesc_simulation_mark.mark
%54 = add nsw i32 %53, 1
store i32 %54, i32* @sesc_simulation_mark.mark
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@sesc_simulation_mark.mark = internal unnamed_addr global i32 0
@sesc_simulation_mark.mark1 = internal unnamed_addr global i32 0
@sesc_simulation_mark.mark2 = internal unnamed_addr global i32 0
@sesc_simulation_mark.tv1 = internal global %struct.timeval zeroinitializer
@.str = [7 x i8] c"SESC_1\00"
@.str.1 = [7 x i8] c"SESC_2\00"
@stderr = global i32 0
@.str.2 = [59 x i8] c"sesc_simulation_mark %d (native) (sim from %d to %d mark)\0A\00"
@.str.3 = [40 x i8] c"sesc_simulation_mark FINISH %lld usesc\0A\00"
define void @sesc_simulation_mark() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = load i32, i32* @sesc_simulation_mark.mark
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %0
%6 = tail call i32 @gettimeofday(%struct.timeval* @sesc_simulation_mark.tv1, i32 0)
%7 = tail call i64 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @atoi(i64 %7)
store i32 %10, i32* @sesc_simulation_mark.mark1
br label %11
11: ; preds = %9, %5
%12 = tail call i64 @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @atoi(i64 %12)
br label %16
16: ; preds = %11, %14
%17 = phi i32 [ %15, %14 ], [ -1, %11 ]
store i32 %17, i32* @sesc_simulation_mark.mark2
br label %18
18: ; preds = %16, %0
%19 = load i32, i32* @sesc_simulation_mark.mark
%20 = load i32, i32* @sesc_simulation_mark.mark1
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = tail call i32 @gettimeofday(%struct.timeval* @sesc_simulation_mark.tv1, i32 0)
%24 = load i32, i32* @sesc_simulation_mark.mark
%25 = load i32, i32* @sesc_simulation_mark.mark1
br label %26
26: ; preds = %22, %18
%27 = phi i32 [ %25, %22 ], [ %20, %18 ]
%28 = phi i32 [ %24, %22 ], [ %19, %18 ]
%29 = load i32, i32* @stderr
%30 = sext i32 %28 to i64
%31 = load i32, i32* @sesc_simulation_mark.mark2
%32 = tail call i32 (i32, i8*, i64, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i64 %30, i32 %27, i32 %31)
%33 = load i32, i32* @sesc_simulation_mark.mark
%34 = load i32, i32* @sesc_simulation_mark.mark2
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %50
36: ; preds = %26
%37 = bitcast %struct.timeval* %1 to i8*
%38 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%39 = bitcast %struct.timeval* %2 to i8*
%40 = call i32 @sesc_tvsub(%struct.timeval* %2, %struct.timeval* %1, %struct.timeval* @sesc_simulation_mark.tv1)
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%42 = load i64, i64* %41
%43 = mul nsw i64 %42, 1000000
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%45 = load i64, i64* %44
%46 = add nsw i64 %43, %45
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 %46)
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %26
%51 = add nsw i32 %33, 1
store i32 %51, i32* @sesc_simulation_mark.mark
ret void
}