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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(scalar_t__ *);
size_t fwrite(scalar_t__ *, int, int, int /*<<< orphan*/ *);
scalar_t__ *malloc(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *fname;
  uint32_t fillval;
  uint32_t *buf;
  uint32_t desired_bytes;
  uint32_t written_bytes;
  int i;
  FILE *f;
  if (argc != 4) {
    fprintf(stderr, "%s: fill_value num_bytes out_file\n", argv[0]);
    return -1;
  }
  fillval = atoi(argv[1]);
  desired_bytes = atoi(argv[2]);
  fname = argv[3];
  f = fopen(fname, "w");
  if (f == NULL) {
    fprintf(stderr, "%s: could not open %s\n", argv[0], fname);
    return -2;
  }
  buf = malloc((1024 * 1024));
  for (i = 0; i < (1024 * 1024) / sizeof(uint32_t); i++)
    buf[i] = fillval;
  written_bytes = 0;
  while (written_bytes < desired_bytes) {
    int bytes_to_write;
    uint32_t remaining_bytes;
    size_t fwrite_elems;
    remaining_bytes = desired_bytes - written_bytes;
    if (remaining_bytes > (1024 * 1024))
      bytes_to_write = (1024 * 1024);
    else
      bytes_to_write = remaining_bytes;
    fwrite_elems = fwrite(buf, bytes_to_write, 1, f);
    assert(fwrite_elems == 1);
    written_bytes += bytes_to_write;
  }
  fclose(f);
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11ca <main+0x4a>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1320 <main+0x1a0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1245 <main+0xc5>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1320 <main+0x1a0>
mov    $0x100000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    $0x20000,%rax
jae    1288 <main+0x108>
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    125a <main+0xda>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1307 <main+0x187>
mov    -0x30(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x100000,-0x58(%rbp)
jle    12c4 <main+0x144>
movl   $0x100000,-0x4c(%rbp)
jmp    12cb <main+0x14b>
mov    -0x58(%rbp),%rax
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x1,-0x60(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movslq -0x4c(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1290 <main+0x110>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    12d2 <main+0x152>
mov    0x8(%rbx),%rdi
call   1090 <atoi@plt>
mov    %rax,%r12
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %rax,%r15
mov    0x18(%rbx),%r13
lea    0xe69(%rip),%rsi
mov    %r13,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12f3 <main+0x173>
mov    %rax,%r14
mov    $0x100000,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movq   %r12,%xmm0
pshufd $0x44,%xmm0,%xmm0
mov    $0x1e,%eax
nopw   0x0(%rax,%rax,1)
movdqu %xmm0,-0xf0(%rbx,%rax,8)
ff ff
movdqu %xmm0,-0xe0(%rbx,%rax,8)
movdqu %xmm0,-0xd0(%rbx,%rax,8)
ff ff
movdqu %xmm0,-0xc0(%rbx,%rax,8)
ff ff
movdqu %xmm0,-0xb0(%rbx,%rax,8)
ff ff
movdqu %xmm0,-0xa0(%rbx,%rax,8)
ff ff
movdqu %xmm0,-0x90(%rbx,%rax,8)
ff ff
movdqu %xmm0,-0x80(%rbx,%rax,8)
movdqu %xmm0,-0x70(%rbx,%rax,8)
movdqu %xmm0,-0x60(%rbx,%rax,8)
movdqu %xmm0,-0x50(%rbx,%rax,8)
movdqu %xmm0,-0x40(%rbx,%rax,8)
movdqu %xmm0,-0x30(%rbx,%rax,8)
movdqu %xmm0,-0x20(%rbx,%rax,8)
movdqu %xmm0,-0x10(%rbx,%rax,8)
movdqu %xmm0,(%rbx,%rax,8)
add    $0x20,%rax
cmp    $0x2001e,%rax
jne    11f0 <main+0x70>
test   %r15,%r15
jle    12be <main+0x13e>
xor    %r13d,%r13d
mov    $0x100000,%ebp
nopl   (%rax)
mov    %r15,%r12
sub    %r13,%r12
cmp    $0x100000,%r12
cmovge %rbp,%r12
mov    %rbx,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10a0 <fwrite@plt>
xor    %edi,%edi
cmp    $0x1,%rax
sete   %dil
call   1050 <assert@plt>
movslq %r12d,%rax
add    %rax,%r13
cmp    %r13,%r15
jg     1280 <main+0x100>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1315 <main+0x195>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd1b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1315 <main+0x195>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd1f(%rip),%rsi
mov    %r13,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"%s: fill_value num_bytes out_file\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [23 x i8] c"%s: could not open %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 4
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %95
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @atoi(i8* %27)
store i64 %28, i64* %7
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i64 @atoi(i8* %31)
store i64 %32, i64* %9
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %37, i32** %12
%38 = load i32*, i32** %12
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %47
40: ; preds = %24
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = load i8*, i8** %6
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %45)
store i32 -2, i32* %3
br label %95
47: ; preds = %24
%48 = call i64* @malloc(i32 1048576)
store i64* %48, i64** %8
store i32 0, i32* %11
br label %49
49: ; preds = %59, %47
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = icmp ult i64 %51, 131072
br i1 %52, label %53, label %62
53: ; preds = %49
%54 = load i64, i64* %7
%55 = load i64*, i64** %8
%56 = load i32, i32* %11
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i64, i64* %55, i64 %57
store i64 %54, i64* %58
br label %59
59: ; preds = %53
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
br label %49
62: ; preds = %49
store i64 0, i64* %10
br label %63
63: ; preds = %77, %62
%64 = load i64, i64* %10
%65 = load i64, i64* %9
%66 = icmp slt i64 %64, %65
br i1 %66, label %67, label %90
67: ; preds = %63
%68 = load i64, i64* %9
%69 = load i64, i64* %10
%70 = sub nsw i64 %68, %69
store i64 %70, i64* %14
%71 = load i64, i64* %14
%72 = icmp sgt i64 %71, 1048576
br i1 %72, label %73, label %74
73: ; preds = %67
store i32 1048576, i32* %13
br label %77
74: ; preds = %67
%75 = load i64, i64* %14
%76 = trunc i64 %75 to i32
store i32 %76, i32* %13
br label %77
77: ; preds = %74, %73
%78 = load i64*, i64** %8
%79 = load i32, i32* %13
%80 = load i32*, i32** %12
%81 = call i64 @fwrite(i64* %78, i32 %79, i32 1, i32* %80)
store i64 %81, i64* %15
%82 = load i64, i64* %15
%83 = icmp eq i64 %82, 1
%84 = zext i1 %83 to i32
%85 = call i32 @assert(i32 %84)
%86 = load i32, i32* %13
%87 = sext i32 %86 to i64
%88 = load i64, i64* %10
%89 = add nsw i64 %88, %87
store i64 %89, i64* %10
br label %63
90: ; preds = %63
%91 = load i32*, i32** %12
%92 = call i32 @fclose(i32* %91)
%93 = load i64*, i64** %8
%94 = call i32 @free(i64* %93)
store i32 0, i32* %3
br label %95
95: ; preds = %90, %40, %18
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"%s: fill_value num_bytes out_file\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [23 x i8] c"%s: could not open %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %91
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i64 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %8
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %1
%22 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %16)
br label %91
23: ; preds = %8
%24 = tail call i64* @malloc(i32 1048576)
%25 = insertelement <2 x i64> poison, i64 %11, i64 0
%26 = shufflevector <2 x i64> %25, <2 x i64> poison, <2 x i32> zeroinitializer
%27 = insertelement <2 x i64> poison, i64 %11, i64 0
%28 = shufflevector <2 x i64> %27, <2 x i64> poison, <2 x i32> zeroinitializer
br label %29
29: ; preds = %29, %23
%30 = phi i64 [ 0, %23 ], [ %70, %29 ]
%31 = getelementptr inbounds i64, i64* %24, i64 %30
%32 = bitcast i64* %31 to <2 x i64>*
store <2 x i64> %26, <2 x i64>* %32
%33 = getelementptr inbounds i64, i64* %31, i64 2
%34 = bitcast i64* %33 to <2 x i64>*
store <2 x i64> %28, <2 x i64>* %34
%35 = or i64 %30, 4
%36 = getelementptr inbounds i64, i64* %24, i64 %35
%37 = bitcast i64* %36 to <2 x i64>*
store <2 x i64> %26, <2 x i64>* %37
%38 = getelementptr inbounds i64, i64* %36, i64 2
%39 = bitcast i64* %38 to <2 x i64>*
store <2 x i64> %28, <2 x i64>* %39
%40 = or i64 %30, 8
%41 = getelementptr inbounds i64, i64* %24, i64 %40
%42 = bitcast i64* %41 to <2 x i64>*
store <2 x i64> %26, <2 x i64>* %42
%43 = getelementptr inbounds i64, i64* %41, i64 2
%44 = bitcast i64* %43 to <2 x i64>*
store <2 x i64> %28, <2 x i64>* %44
%45 = or i64 %30, 12
%46 = getelementptr inbounds i64, i64* %24, i64 %45
%47 = bitcast i64* %46 to <2 x i64>*
store <2 x i64> %26, <2 x i64>* %47
%48 = getelementptr inbounds i64, i64* %46, i64 2
%49 = bitcast i64* %48 to <2 x i64>*
store <2 x i64> %28, <2 x i64>* %49
%50 = or i64 %30, 16
%51 = getelementptr inbounds i64, i64* %24, i64 %50
%52 = bitcast i64* %51 to <2 x i64>*
store <2 x i64> %26, <2 x i64>* %52
%53 = getelementptr inbounds i64, i64* %51, i64 2
%54 = bitcast i64* %53 to <2 x i64>*
store <2 x i64> %28, <2 x i64>* %54
%55 = or i64 %30, 20
%56 = getelementptr inbounds i64, i64* %24, i64 %55
%57 = bitcast i64* %56 to <2 x i64>*
store <2 x i64> %26, <2 x i64>* %57
%58 = getelementptr inbounds i64, i64* %56, i64 2
%59 = bitcast i64* %58 to <2 x i64>*
store <2 x i64> %28, <2 x i64>* %59
%60 = or i64 %30, 24
%61 = getelementptr inbounds i64, i64* %24, i64 %60
%62 = bitcast i64* %61 to <2 x i64>*
store <2 x i64> %26, <2 x i64>* %62
%63 = getelementptr inbounds i64, i64* %61, i64 2
%64 = bitcast i64* %63 to <2 x i64>*
store <2 x i64> %28, <2 x i64>* %64
%65 = or i64 %30, 28
%66 = getelementptr inbounds i64, i64* %24, i64 %65
%67 = bitcast i64* %66 to <2 x i64>*
store <2 x i64> %26, <2 x i64>* %67
%68 = getelementptr inbounds i64, i64* %66, i64 2
%69 = bitcast i64* %68 to <2 x i64>*
store <2 x i64> %28, <2 x i64>* %69
%70 = add nuw nsw i64 %30, 32
%71 = icmp eq i64 %70, 131072
br i1 %71, label %72, label %29
72: ; preds = %29
%73 = icmp sgt i64 %14, 0
br i1 %73, label %74, label %88
74: ; preds = %72, %74
%75 = phi i64 [ %86, %74 ], [ 0, %72 ]
%76 = sub nsw i64 %14, %75
%77 = icmp slt i64 %76, 1048576
%78 = select i1 %77, i64 %76, i64 1048576
%79 = trunc i64 %78 to i32
%80 = tail call i64 @fwrite(i64* %24, i32 %79, i32 1, i32* %17)
%81 = icmp eq i64 %80, 1
%82 = zext i1 %81 to i32
%83 = tail call i32 @assert(i32 %82)
%84 = shl i64 %78, 32
%85 = ashr exact i64 %84, 32
%86 = add nsw i64 %85, %75
%87 = icmp sgt i64 %14, %86
br i1 %87, label %74, label %88
88: ; preds = %74, %72
%89 = tail call i32 @fclose(i32* %17)
%90 = tail call i32 @free(i64* %24)
br label %91
91: ; preds = %88, %19, %4
%92 = phi i32 [ -1, %4 ], [ -2, %19 ], [ 0, %88 ]
ret i32 %92
}