#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 */
typedef int /*<<< orphan*/ msg;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Usage: workertest [seconds to run]\n");
    return 1;
  }
  int run_time = atoi(argv[1]);
  for (int i = 0; i < run_time; i++) {
    char msg[1024];
    snprintf(msg, sizeof(msg), "Msg %d\n", i);
    if (i % 3 == 0) {
      fputs(msg, stderr);
      fflush(stderr);
    } else {
      fputs(msg, stdout);
      fflush(stdout);
    }
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a4 <main+0x44>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1260 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1259 <main+0xf9>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%ecx
mov    $0x400,%esi
lea    0xe47(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    121e <main+0xbe>
lea    -0x420(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    1241 <main+0xe1>
lea    -0x420(%rbp),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bb <main+0x5b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
cmp    $0x2,%edi
jne    1201 <main+0xa1>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
jle    121d <main+0xbd>
mov    %eax,%r15d
xor    %ebp,%ebp
mov    %rsp,%rbx
mov    0x2e3e(%rip),%r12
jmp    11c7 <main+0x67>
nopl   0x0(%rax)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
mov    0x0(%r13),%edi
call   1060 <fflush@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
je     121d <main+0xbd>
mov    %ebp,%eax
mov    $0xaaaaaaab,%ecx
imul   %rcx,%rax
shr    $0x21,%rax
lea    (%rax,%rax,2),%r14d
mov    %rbx,%rdi
mov    $0x400,%esi
lea    0xe3b(%rip),%rdx
mov    %ebp,%ecx
call   1030 <snprintf@plt>
mov    %r12,%r13
cmp    %ebp,%r14d
jne    11a0 <main+0x40>
mov    0x2de1(%rip),%r13
jmp    11a0 <main+0x40>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    121f <main+0xbf>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: workertest [seconds to run]\0A\00"
@.str.1 = [8 x i8] c"Msg %d\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %48
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
store i32 0, i32* %7
br label %19
19: ; preds = %44, %14
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %47
23: ; preds = %19
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = load i32, i32* %7
%26 = call i32 @snprintf(i8* %24, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %7
%28 = srem i32 %27, 3
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %23
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%32 = load i32, i32* @stderr
%33 = call i32 @fputs(i8* %31, i32 %32)
%34 = load i32, i32* @stderr
%35 = call i32 @fflush(i32 %34)
br label %42
36: ; preds = %23
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%38 = load i32, i32* @stdout
%39 = call i32 @fputs(i8* %37, i32 %38)
%40 = load i32, i32* @stdout
%41 = call i32 @fflush(i32 %40)
br label %42
42: ; preds = %36, %30
%43 = call i32 @sleep(i32 1)
br label %44
44: ; preds = %42
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %19
47: ; preds = %19
store i32 0, i32* %3
br label %48
48: ; preds = %47, %11
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: workertest [seconds to run]\0A\00"
@.str.1 = [8 x i8] c"Msg %d\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %28
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %8
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ 0, %13 ], [ %26, %15 ]
%17 = call i32 @snprintf(i8* %14, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = urem i32 %16, 3
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i32* @stderr, i32* @stdout
%21 = load i32, i32* %20
%22 = call i32 @fputs(i8* %14, i32 %21)
%23 = load i32, i32* %20
%24 = call i32 @fflush(i32 %23)
%25 = call i32 @sleep(i32 1)
%26 = add nuw nsw i32 %16, 1
%27 = icmp eq i32 %26, %11
br i1 %27, label %28, label %15
28: ; preds = %15, %8, %5
%29 = phi i32 [ 1, %5 ], [ 0, %8 ], [ 0, %15 ]
ret i32 %29
}