#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 timer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ timer_continue(struct timer *);
int /*<<< orphan*/ timer_destroy(struct timer **);
int /*<<< orphan*/ timer_elapsed(struct timer *, int /*<<< orphan*/ *);
struct timer *timer_new();
int /*<<< orphan*/ timer_stop(struct timer *);
int main(int argc, char *argv[]) {
  struct timer *timer = timer_new();
  sleep(1);
  printf("Elapsed: %lu ms\n", timer_elapsed(timer, NULL));
  timer_stop(timer);
  sleep(1);
  printf("Elapsed: %lu ms\n", timer_elapsed(timer, NULL));
  timer_continue(timer);
  sleep(1);
  printf("Elapsed: %lu ms\n", timer_elapsed(timer, NULL));
  timer_destroy(&timer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <timer_new@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <timer_elapsed@plt>
mov    %eax,%esi
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <timer_stop@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <timer_elapsed@plt>
mov    %eax,%esi
lea    0xe21(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <timer_continue@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <timer_elapsed@plt>
mov    %eax,%esi
lea    0xdf3(%rip),%rdi
call   1050 <printf@plt>
lea    -0x18(%rbp),%rdi
call   1040 <timer_destroy@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <timer_new@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <timer_elapsed@plt>
lea    0xe63(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <timer_stop@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <timer_elapsed@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1090 <timer_continue@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <timer_elapsed@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1040 <timer_destroy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timer = type { i32 }
@.str = [17 x i8] c"Elapsed: %lu ms\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timer*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call %struct.timer* (...) @timer_new()
store %struct.timer* %7, %struct.timer** %6
%8 = call i32 @sleep(i32 1)
%9 = load %struct.timer*, %struct.timer** %6
%10 = call i32 @timer_elapsed(%struct.timer* %9, i32* null)
%11 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load %struct.timer*, %struct.timer** %6
%13 = call i32 @timer_stop(%struct.timer* %12)
%14 = call i32 @sleep(i32 1)
%15 = load %struct.timer*, %struct.timer** %6
%16 = call i32 @timer_elapsed(%struct.timer* %15, i32* null)
%17 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load %struct.timer*, %struct.timer** %6
%19 = call i32 @timer_continue(%struct.timer* %18)
%20 = call i32 @sleep(i32 1)
%21 = load %struct.timer*, %struct.timer** %6
%22 = call i32 @timer_elapsed(%struct.timer* %21, i32* null)
%23 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 @timer_destroy(%struct.timer** %6)
ret i32 0
}

LLVM IR (-O2):
%struct.timer = type { i32 }
@.str = [17 x i8] c"Elapsed: %lu ms\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timer*
%4 = bitcast %struct.timer** %3 to i8*
%5 = tail call %struct.timer* (...) @timer_new()
store %struct.timer* %5, %struct.timer** %3
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32 @timer_elapsed(%struct.timer* %5, i32* null)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @timer_stop(%struct.timer* %5)
%10 = tail call i32 @sleep(i32 1)
%11 = tail call i32 @timer_elapsed(%struct.timer* %5, i32* null)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @timer_continue(%struct.timer* %5)
%14 = tail call i32 @sleep(i32 1)
%15 = tail call i32 @timer_elapsed(%struct.timer* %5, i32* null)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @timer_destroy(%struct.timer** %3)
ret i32 0
}