#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 O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int random();
int /*<<< orphan*/ srandom(int);
int /*<<< orphan*/ stderr;
int write(int, int *, int);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    fprintf(stderr, "usage: intgen <file> <count> <seed>\n");
    exit(1);
  }
  char *infile = argv[1];
  int count = atoi(argv[2]);
  int seed = atoi(argv[3]);
  assert(count > 0);
  (void)srandom(seed);
  int fd = open(infile, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
  assert(fd > -1);
  int i;
  for (i = 0; i < count; i++) {
    int value = (random() % 50000) - 25000;
    printf("%d\n", value);
    int rc = write(fd, &value, sizeof(int));
    assert(rc == sizeof(int));
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11df <main+0x3f>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x20(%rbp),%edi
call   1030 <srandom@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
mov    0x2dc0(%rip),%rax
or     (%rax),%esi
mov    0x2daf(%rip),%rax
or     (%rax),%esi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12d6 <main+0x136>
mov    $0x0,%al
call   1090 <random@plt>
mov    $0xc350,%ecx
cltd
idiv   %ecx
sub    $0x61a8,%edx
mov    %edx,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xd8b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    $0x4,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    126c <main+0xcc>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    12a0 <main+0x100>
mov    %rsi,%rbp
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
mov    0x18(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
xor    %edi,%edi
test   %ebx,%ebx
setg   %dil
call   1070 <assert@plt>
mov    %ebp,%edi
call   1030 <srandom@plt>
mov    0x2dd0(%rip),%rax
mov    0x2e09(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2df6(%rip),%rax
or     (%rax),%esi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1070 <assert@plt>
test   %ebx,%ebx
jle    128c <main+0xec>
lea    0xdff(%rip),%r14
lea    0x4(%rsp),%r15
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <random@plt>
cltq
imul   $0x14f8b589,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0xc350,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0xffff9e58,%esi
mov    %esi,0x4(%rsp)
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1070 <assert@plt>
add    $0xffffffff,%ebx
jne    1230 <main+0x90>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"usage: intgen <file> <count> <seed>\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
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, 4
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %7
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %7
%32 = icmp sgt i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* %8
%36 = call i32 @srandom(i32 %35)
%37 = load i8*, i8** %6
%38 = load i32, i32* @O_WRONLY
%39 = load i32, i32* @O_CREAT
%40 = or i32 %38, %39
%41 = load i32, i32* @O_TRUNC
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IRWXU
%44 = call i32 @open(i8* %37, i32 %42, i32 %43)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = icmp sgt i32 %45, -1
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
store i32 0, i32* %10
br label %49
49: ; preds = %66, %19
%50 = load i32, i32* %10
%51 = load i32, i32* %7
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %69
53: ; preds = %49
%54 = call i32 (...) @random()
%55 = srem i32 %54, 50000
%56 = sub nsw i32 %55, 25000
store i32 %56, i32* %11
%57 = load i32, i32* %11
%58 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %9
%60 = call i32 @write(i32 %59, i32* %11, i32 4)
store i32 %60, i32* %12
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = icmp eq i64 %62, 4
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
br label %66
66: ; preds = %53
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
store i32 %68, i32* %10
br label %49
69: ; preds = %49
%70 = load i32, i32* %9
%71 = call i32 @close(i32 %70)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"usage: intgen <file> <count> <seed>\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 4
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = icmp sgt i32 %14, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = tail call i32 @srandom(i32 %17)
%22 = load i32, i32* @O_WRONLY
%23 = load i32, i32* @O_CREAT
%24 = or i32 %23, %22
%25 = load i32, i32* @O_TRUNC
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IRWXU
%28 = tail call i32 @open(i8* %11, i32 %26, i32 %27)
%29 = xor i32 %28, -1
%30 = lshr i32 %29, 31
%31 = tail call i32 @assert(i32 %30)
br i1 %18, label %32, label %46
32: ; preds = %9
%33 = bitcast i32* %3 to i8*
br label %34
34: ; preds = %32, %34
%35 = phi i32 [ 0, %32 ], [ %44, %34 ]
%36 = tail call i32 (...) @random()
%37 = srem i32 %36, 50000
%38 = add nsw i32 %37, -25000
store i32 %38, i32* %3
%39 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = call i32 @write(i32 %28, i32* %3, i32 4)
%41 = icmp eq i32 %40, 4
%42 = zext i1 %41 to i32
%43 = tail call i32 @assert(i32 %42)
%44 = add nuw nsw i32 %35, 1
%45 = icmp eq i32 %44, %14
br i1 %45, label %46, label %34
46: ; preds = %34, %9
%47 = tail call i32 @close(i32 %28)
ret i32 0
}