#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 tv_sec;
  scalar_t__ tv_usec;
};
struct mq_attr {
  int mq_msgsize;
};
typedef scalar_t__ mqd_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_RDONLY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *malloc(int);
scalar_t__ mq_getattr(scalar_t__, struct mq_attr *);
scalar_t__ mq_open(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ mq_receive(scalar_t__, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  mqd_t mq;
  int taille;
  char *buffer;
  long int duree;
  struct mq_attr attr;
  struct timeval heure;
  struct timeval *recue;
  if (argc != 2) {
    fprintf(stderr, "usage: %s nom_file_messagen", argv[0]);
    exit(EXIT_FAILURE);
  }
  mq = mq_open(argv[1], O_RDONLY | O_CREAT, 0600, NULL);
  if (mq == (mqd_t)-1) {
    perror(argv[1]);
    exit(EXIT_FAILURE);
  }
  if (mq_getattr(mq, &attr) != 0) {
    perror("mq_getattr");
    exit(EXIT_FAILURE);
  }
  taille = attr.mq_msgsize;
  buffer = malloc(taille);
  if (buffer == NULL) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  recue = (struct timeval *)buffer;
  while (1) {
    mq_receive(mq, buffer, taille, NULL);
    gettimeofday(&heure, NULL);
    duree = heure.tv_sec - recue->tv_sec;
    duree *= 1000000;
    duree += heure.tv_usec - recue->tv_usec;
    fprintf(stdout, "%ld usecn\n", duree);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11cc <main+0x4c>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    0x2e14(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <mq_open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    121e <main+0x9e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <mq_getattr@plt>
cmp    $0x0,%rax
je     124f <main+0xcf>
lea    0xde0(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1286 <main+0x106>
lea    0xdb4(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <mq_receive@plt>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x68(%rbp)
mov    %rax,-0x30(%rbp)
imul   $0xf4240,-0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x60(%rbp)
add    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    %rax,-0x30(%rbp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xd30(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    128e <main+0x10e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1254 <main+0xd4>
mov    0x8(%rbx),%rdi
mov    0x2e3b(%rip),%rax
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x180,%edx
xor    %ecx,%ecx
call   1050 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     1270 <main+0xf0>
mov    %rax,%r14
mov    %rsp,%rsi
mov    %rax,%rdi
call   10a0 <mq_getattr@plt>
test   %rax,%rax
jne    1276 <main+0xf6>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     127f <main+0xff>
mov    %rax,%rbx
lea    0x8(%rsp),%r15
mov    0x2dc1(%rip),%r13
lea    0xe28(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1070 <mq_receive@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rdx
sub    (%rbx),%rax
imul   $0xf4240,%rax,%rax
sub    0x8(%rbx),%rdx
add    %rax,%rdx
mov    0x0(%r13),%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1210 <main+0x90>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd99(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    128b <main+0x10b>
mov    0x8(%rbx),%rdi
jmp    1286 <main+0x106>
lea    0xd9f(%rip),%rdi
jmp    1286 <main+0x106>
lea    0xda1(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32 }
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s nom_file_messagen\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [11 x i8] c"mq_getattr\00"
@.str.2 = [7 x i8] c"malloc\00"
@stdout = global i32 0
@.str.3 = [11 x i8] c"%ld usecn\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.mq_attr
%11 = alloca %struct.timeval
%12 = alloca %struct.timeval*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = load i32, i32* @O_CREAT
%29 = or i32 %27, %28
%30 = call i64 @mq_open(i8* %26, i32 %29, i32 384, i32* null)
store i64 %30, i64* %6
%31 = load i64, i64* %6
%32 = icmp eq i64 %31, -1
br i1 %32, label %33, label %40
33: ; preds = %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @perror(i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %23
%41 = load i64, i64* %6
%42 = call i64 @mq_getattr(i64 %41, %struct.mq_attr* %10)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %40
%49 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 0
%50 = load i32, i32* %49
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = call i8* @malloc(i32 %51)
store i8* %52, i8** %8
%53 = load i8*, i8** %8
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %59
55: ; preds = %48
%56 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %48
%60 = load i8*, i8** %8
%61 = bitcast i8* %60 to %struct.timeval*
store %struct.timeval* %61, %struct.timeval** %12
br label %62
62: ; preds = %59, %62
%63 = load i64, i64* %6
%64 = load i8*, i8** %8
%65 = load i32, i32* %7
%66 = call i32 @mq_receive(i64 %63, i8* %64, i32 %65, i32* null)
%67 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%69 = load i64, i64* %68
%70 = load %struct.timeval*, %struct.timeval** %12
%71 = getelementptr inbounds %struct.timeval, %struct.timeval* %70, i32 0, i32 0
%72 = load i64, i64* %71
%73 = sub nsw i64 %69, %72
store i64 %73, i64* %9
%74 = load i64, i64* %9
%75 = mul nsw i64 %74, 1000000
store i64 %75, i64* %9
%76 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%77 = load i64, i64* %76
%78 = load %struct.timeval*, %struct.timeval** %12
%79 = getelementptr inbounds %struct.timeval, %struct.timeval* %78, i32 0, i32 1
%80 = load i64, i64* %79
%81 = sub nsw i64 %77, %80
%82 = load i64, i64* %9
%83 = add nsw i64 %82, %81
store i64 %83, i64* %9
%84 = load i32, i32* @stdout
%85 = load i64, i64* %9
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %85)
br label %62
}

LLVM IR (-O2):
%struct.mq_attr = type { i32 }
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s nom_file_messagen\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [11 x i8] c"mq_getattr\00"
@.str.2 = [7 x i8] c"malloc\00"
@stdout = global i32 0
@.str.3 = [11 x i8] c"%ld usecn\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.mq_attr
%4 = alloca %struct.timeval
%5 = bitcast %struct.mq_attr* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = load i32, i32* @O_CREAT
%19 = or i32 %18, %17
%20 = tail call i64 @mq_open(i8* %16, i32 %19, i32 384, i32* null)
%21 = icmp eq i64 %20, -1
br i1 %21, label %22, label %27
22: ; preds = %14
%23 = load i8*, i8** %15
%24 = tail call i32 @perror(i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %14
%28 = call i64 @mq_getattr(i64 %20, %struct.mq_attr* %3)
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %27
%35 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 0
%36 = load i32, i32* %35
%37 = call i8* @malloc(i32 %36)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %34
%44 = bitcast i8* %37 to %struct.timeval*
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %44, i64 0, i32 0
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %44, i64 0, i32 1
br label %49
49: ; preds = %49, %43
%50 = call i32 @mq_receive(i64 %20, i8* %37, i32 %36, i32* null)
%51 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%52 = load i64, i64* %45
%53 = load i64, i64* %46
%54 = sub nsw i64 %52, %53
%55 = mul nsw i64 %54, 1000000
%56 = load i64, i64* %47
%57 = load i64, i64* %48
%58 = sub i64 %56, %57
%59 = add nsw i64 %58, %55
%60 = load i32, i32* @stdout
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %59)
br label %49
}