#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 */

/* Variables and functions */
int /*<<< orphan*/ send_msgq(int, int, char *);
int /*<<< orphan*/ show_time();
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, int);
scalar_t__ time(int /*<<< orphan*/ *);
int test() {
  const int STRLEN = 60;
  const int REPEAT_COUNT = 60000;
  int i;
  char str[STRLEN];
  show_time();
  for (i = 0; i < REPEAT_COUNT; i++) {
    sprintf(str, "%u: %d", (unsigned)time(NULL), i);
    send_msgq(0x0ADA5000, 9, str);
  }
  show_time();
  return 0;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x3c,-0x4(%rbp)
movl   $0xea60,-0x8(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <show_time@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xea60,-0xc(%rbp)
jge    11b7 <test+0x77>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edx
mov    -0xc(%rbp),%ecx
lea    -0x60(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <sprintf@plt>
mov    $0xada5000,%edi
mov    $0x9,%esi
lea    -0x60(%rbp),%rdx
call   1030 <send_msgq@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116b <test+0x2b>
mov    $0x0,%al
call   1040 <show_time@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <show_time@plt>
lea    0xea7(%rip),%r14
mov    %rsp,%r15
nopl   0x0(%rax)
xor    %edi,%edi
call   1050 <time@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
mov    %ebx,%ecx
call   1060 <sprintf@plt>
mov    $0xada5000,%edi
mov    $0x9,%esi
mov    %r15,%rdx
call   1030 <send_msgq@plt>
add    $0x1,%ebx
cmp    $0xea60,%ebx
jne    1160 <test+0x20>
xor    %eax,%eax
call   1040 <show_time@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%u: %d\00"
define i32 @test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 60, i32* %1
store i32 60000, i32* %2
%5 = call i8* @llvm.stacksave()
store i8* %5, i8** %4
%6 = alloca i8, i64 60
%7 = call i32 (...) @show_time()
store i32 0, i32* %3
br label %8
8: ; preds = %17, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 60000
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = call i64 @time(i32* null)
%13 = trunc i64 %12 to i32
%14 = load i32, i32* %3
%15 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = call i32 @send_msgq(i32 182079488, i32 9, i8* %6)
br label %17
17: ; preds = %11
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %8
20: ; preds = %8
%21 = call i32 (...) @show_time()
%22 = load i8*, i8** %4
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%u: %d\00"
define i32 @test() {
%1 = alloca [60 x i8]
%2 = getelementptr inbounds [60 x i8], [60 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @show_time()
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %10, %4 ]
%6 = call i64 @time(i32* null)
%7 = trunc i64 %6 to i32
%8 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %5)
%9 = call i32 @send_msgq(i32 182079488, i32 9, i8* %2)
%10 = add nuw nsw i32 %5, 1
%11 = icmp eq i32 %10, 60000
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = call i32 (...) @show_time()
ret i32 0
}