#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 long long uint32_t;
typedef int /*<<< orphan*/ num;

/* Variables and functions */
#define EAGAIN 132
#define EBUSY 131
#define EDEADLK 130
#define EINTR 129
#define ETXTBSY 128
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long long, ...);
int fwrite(long long *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
int generate_data(long long num_nums) {
  uint32_t num;
  for (num = 0; num < num_nums; ++num) {
    while (fwrite(&num, sizeof(num), 1, stdout) != 1) {
      switch (errno) {
      case EINTR:
      case EBUSY:
      case EDEADLK:
      case EAGAIN:
      case ETXTBSY:
        break;
      default:
        fprintf(stderr, "Failed to write number %d, err %d: %s\n", num, errno,
                strerror(errno));
        return -1;
        break;
      }
    }
  }
  fprintf(stderr, "Wrote %d sequential numbers.\n", num);
  return 0;
}


x86 assembly (clang, -O0):
<generate_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    120b <generate_data+0xdb>
jmp    1157 <generate_data+0x27>
mov    0x2e72(%rip),%rax
mov    (%rax),%ecx
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
cmp    $0x1,%eax
je     11f5 <generate_data+0xc5>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x4,%eax
ja     119b <generate_data+0x6b>
jmp    1196 <generate_data+0x66>
jmp    11f0 <generate_data+0xc0>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    %rax,%r8
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <generate_data+0xfd>
jmp    1157 <generate_data+0x27>
jmp    11fa <generate_data+0xca>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <generate_data+0x14>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movq   $0x0,(%rsp)
xor    %r14d,%r14d
test   %rdi,%rdi
jle    11a9 <generate_data+0x79>
mov    %rdi,%r12
mov    0x2e7b(%rip),%rbp
mov    %rsp,%r15
mov    0x2e79(%rip),%r13
jmp    117c <generate_data+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%ebx
lea    -0x80(%rbx),%eax
cmp    $0x5,%eax
jae    11c4 <generate_data+0x94>
mov    0x0(%rbp),%ecx
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
cmp    $0x1,%eax
jne    1170 <generate_data+0x40>
mov    (%rsp),%rdx
add    $0x1,%rdx
mov    %rdx,(%rsp)
cmp    %r12,%rdx
jl     117c <generate_data+0x4c>
jmp    11ab <generate_data+0x7b>
xor    %edx,%edx
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11f6 <generate_data+0xc6>
mov    0x2e15(%rip),%rax
mov    (%rax),%ebp
mov    (%rsp),%r14
mov    %ebx,%edi
call   1050 <strerror@plt>
lea    0xe21(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [39 x i8] c"Failed to write number %d, err %d: %s\0A\00"
@.str.1 = [30 x i8] c"Wrote %d sequential numbers.\0A\00"
define i32 @generate_data(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 0, i64* %4
br label %5
5: ; preds = %26, %1
%6 = load i64, i64* %4
%7 = load i64, i64* %3
%8 = icmp slt i64 %6, %7
br i1 %8, label %9, label %29
9: ; preds = %5
br label %10
10: ; preds = %24, %9
%11 = load i32, i32* @stdout
%12 = call i32 @fwrite(i64* %4, i32 8, i32 1, i32 %11)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* @errno
switch i32 %15, label %17 [
i32 129, label %16
i32 131, label %16
i32 130, label %16
i32 132, label %16
i32 128, label %16
]
16: ; preds = %14, %14, %14, %14, %14
br label %24
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i64, i64* %4
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %19, i32 %20, i8* %22)
store i32 -1, i32* %2
br label %33
24: ; preds = %16
br label %10
25: ; preds = %10
br label %26
26: ; preds = %25
%27 = load i64, i64* %4
%28 = add nsw i64 %27, 1
store i64 %28, i64* %4
br label %5
29: ; preds = %5
%30 = load i32, i32* @stderr
%31 = load i64, i64* %4
%32 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %31)
store i32 0, i32* %2
br label %33
33: ; preds = %29, %17
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@stdout = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [39 x i8] c"Failed to write number %d, err %d: %s\0A\00"
@.str.1 = [30 x i8] c"Wrote %d sequential numbers.\0A\00"
define i32 @generate_data(i64 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%4 = icmp sgt i64 %0, 0
br i1 %4, label %5, label %23
5: ; preds = %1, %13
%6 = load i32, i32* @stdout
%7 = call i32 @fwrite(i64* %2, i32 8, i32 1, i32 %6)
%8 = icmp eq i32 %7, 1
br i1 %8, label %19, label %9
9: ; preds = %5
%10 = load i32, i32* @errno
%11 = add i32 %10, -128
%12 = icmp ult i32 %11, 5
br i1 %12, label %13, label %14
13: ; preds = %9, %19
br label %5
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i64, i64* %2
%17 = call i8* @strerror(i32 %10)
%18 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %16, i32 %10, i8* %17)
br label %27
19: ; preds = %5
%20 = load i64, i64* %2
%21 = add nsw i64 %20, 1
store i64 %21, i64* %2
%22 = icmp slt i64 %21, %0
br i1 %22, label %13, label %23
23: ; preds = %19, %1
%24 = phi i64 [ 0, %1 ], [ %21, %19 ]
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %24)
br label %27
27: ; preds = %23, %14
%28 = phi i32 [ -1, %14 ], [ 0, %23 ]
ret i32 %28
}