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

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ FALLOC_FL_KEEP_SIZE;
int /*<<< orphan*/ O_WRONLY;
int close(int);
int /*<<< orphan*/ errno;
int fallocate(int, int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strtoll(char *, char **, int);
int main(int argc, char *argv[]) {
  char *tmp;
  loff_t size;
  int fd, ret;
  if (argc < 3) {
    printf("Usage: falloc <file> <size>\n");
    return EXIT_FAILURE;
  }
  size = strtoll(argv[2], &tmp, 10);
  if (*tmp != 0 || size <= 0) {
    printf("%s is not a valid size.\n", argv[2]);
    return EXIT_FAILURE;
  }
  fd = open(argv[1], O_WRONLY);
  if (fd < 0) {
    printf("Could not open %s: %s\n", argv[1], strerror(errno));
    return EXIT_FAILURE;
  }
  ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, size);
  if (ret < 0) {
    printf("Could not fallocate %lu bytes: %s\n", size, strerror(errno));
    return EXIT_FAILURE;
  }
  ret = close(fd);
  if (ret < 0) {
    printf("Could not close file: %s\n", strerror(errno));
    return EXIT_FAILURE;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119f <main+0x3f>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1304 <main+0x1a4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtoll@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d2 <main+0x72>
cmpl   $0x0,-0x1c(%rbp)
jg     11f9 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1304 <main+0x1a4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    125c <main+0xfc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1304 <main+0x1a4>
mov    -0x20(%rbp),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%ecx
xor    %edx,%edx
call   1050 <fallocate@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12b8 <main+0x158>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%esi
mov    %rax,%rdx
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1304 <main+0x1a4>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12fd <main+0x19d>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1304 <main+0x1a4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jg     118e <main+0x1e>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
jmp    1270 <main+0x100>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1070 <strtoll@plt>
mov    %eax,%r14d
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1212 <main+0xa2>
test   %r14d,%r14d
jle    1212 <main+0xa2>
mov    0x8(%rbx),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1226 <main+0xb6>
mov    %eax,%ebp
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
mov    %r14d,%ecx
call   1060 <fallocate@plt>
test   %eax,%eax
js     124e <main+0xde>
mov    %ebp,%edi
call   1050 <close@plt>
test   %eax,%eax
jns    1279 <main+0x109>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe46(%rip),%rdi
mov    %rax,%rsi
jmp    121d <main+0xad>
mov    0x10(%rbx),%rsi
lea    0xde3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1270 <main+0x100>
mov    0x8(%rbx),%rbx
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdda(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1270 <main+0x100>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdcd(%rip),%rdi
mov    %r14d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: falloc <file> <size>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"%s is not a valid size.\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [23 x i8] c"Could not open %s: %s\0A\00"
@errno = global i32 0
@FALLOC_FL_KEEP_SIZE = global i32 0
@.str.3 = [35 x i8] c"Could not fallocate %lu bytes: %s\0A\00"
@.str.4 = [26 x i8] c"Could not close file: %s\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %73
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @strtoll(i8* %18, i8** %6, i32 10)
store i32 %19, i32* %7
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %15
%25 = load i32, i32* %7
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24, %15
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
store i32 %32, i32* %3
br label %73
33: ; preds = %24
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_WRONLY
%38 = call i32 @open(i8* %36, i32 %37)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %3
br label %73
49: ; preds = %33
%50 = load i32, i32* %8
%51 = load i32, i32* @FALLOC_FL_KEEP_SIZE
%52 = load i32, i32* %7
%53 = call i32 @fallocate(i32 %50, i32 %51, i32 0, i32 %52)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %49
%57 = load i32, i32* %7
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %57, i8* %59)
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %3
br label %73
62: ; preds = %49
%63 = load i32, i32* %8
%64 = call i32 @close(i32 %63)
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %62
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
store i32 %71, i32* %3
br label %73
72: ; preds = %62
store i32 0, i32* %3
br label %73
73: ; preds = %72, %67, %56, %41, %27, %12
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"%s is not a valid size.\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [23 x i8] c"Could not open %s: %s\0A\00"
@errno = global i32 0
@FALLOC_FL_KEEP_SIZE = global i32 0
@.str.3 = [35 x i8] c"Could not fallocate %lu bytes: %s\0A\00"
@.str.4 = [26 x i8] c"Could not close file: %s\0A\00"
@str = [28 x i8] c"Usage: falloc <file> <size>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
br label %51
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = call i32 @strtoll(i8* %11, i8** %3, i32 10)
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
%16 = icmp slt i32 %12, 1
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %22
18: ; preds = %9
%19 = load i8*, i8** %10
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
br label %51
22: ; preds = %9
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_WRONLY
%26 = tail call i32 @open(i8* %24, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load i8*, i8** %23
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
br label %51
34: ; preds = %22
%35 = load i32, i32* @FALLOC_FL_KEEP_SIZE
%36 = tail call i32 @fallocate(i32 %26, i32 %35, i32 0, i32 %12)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i32, i32* @errno
%40 = tail call i8* @strerror(i32 %39)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %12, i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
br label %51
43: ; preds = %34
%44 = tail call i32 @close(i32 %26)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i32, i32* @errno
%48 = tail call i8* @strerror(i32 %47)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
br label %51
51: ; preds = %43, %46, %38, %28, %18, %6
%52 = phi i32 [ %8, %6 ], [ %21, %18 ], [ %33, %28 ], [ %42, %38 ], [ %50, %46 ], [ 0, %43 ]
ret i32 %52
}