#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int, int);
int pwrite(int, char *, int, unsigned int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
unsigned int strtoul(char *, char **, int);
int main(int argc, char **argv) {
  int p_size;
  unsigned int offset;
  char *filename;
  int fd;
  char buf[] = "+++";
  char *end;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <filename> <offset>(KB)\n", argv[0]);
    exit(1);
  }
  filename = argv[1];
  offset = strtoul(argv[2], &end, 10);
  if (*end) {
    fprintf(stderr, "<offset> parameter should be integer\n");
    exit(1);
  }
  fd = open(filename, O_CREAT | O_RDWR, 0644);
  if (fd == -1) {
    fprintf(stderr, "Opening %s fails (%s)\n", filename, strerror(errno));
    return 1;
  }
  p_size = pwrite(fd, buf, 1, offset);
  if (p_size != 1) {
    fprintf(stderr, "pwrite %s fails (%s)\n", filename, strerror(errno));
    close(fd);
    return 1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe74(%rip),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c1 <main+0x51>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     1214 <main+0xa4>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    0x2db8(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1287 <main+0x117>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1305 <main+0x195>
mov    -0x24(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%ecx
mov    $0x1,%edx
call   1050 <pwrite@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     12f6 <main+0x186>
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1305 <main+0x195>
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x2b2b2b,0xc(%rsp)
cmp    $0x3,%edi
jne    1279 <main+0x109>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   1070 <strtoul@plt>
mov    %eax,%r15d
mov    0x10(%rsp),%rax
cmpb   $0x0,(%rax)
jne    129d <main+0x12d>
mov    0x2e3e(%rip),%rax
mov    0x2e1f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1a4,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1202 <main+0x92>
mov    %eax,%ebx
lea    0xc(%rsp),%rsi
mov    $0x1,%ebp
mov    %eax,%edi
mov    $0x1,%edx
mov    %r15d,%ecx
call   1050 <pwrite@plt>
cmp    $0x1,%eax
jne    1236 <main+0xc6>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %ebp,%ebp
jmp    126c <main+0xfc>
mov    0x2dc7(%rip),%rax
mov    (%rax),%ebx
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe29(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebp
jmp    126c <main+0xfc>
mov    0x2d93(%rip),%rax
mov    (%rax),%r15d
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe0b(%rip),%rsi
mov    %r15d,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd74(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@__const.main.buf = [4 x i8] c"+++\00"
@stderr = global i32 0
@.str = [35 x i8] c"Usage: %s <filename> <offset>(KB)\0A\00"
@.str.1 = [38 x i8] c"<offset> parameter should be integer\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.2 = [23 x i8] c"Opening %s fails (%s)\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"pwrite %s fails (%s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [4 x i8]
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [4 x i8]* %10 to i8*
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
store i8* %25, i8** %8
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @strtoul(i8* %28, i8** %11, i32 10)
store i32 %29, i32* %7
%30 = load i8*, i8** %11
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %22
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %22
%38 = load i8*, i8** %8
%39 = load i32, i32* @O_CREAT
%40 = load i32, i32* @O_RDWR
%41 = or i32 %39, %40
%42 = call i32 @open(i8* %38, i32 %41, i32 420)
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %51
45: ; preds = %37
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %8
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %47, i8* %49)
store i32 1, i32* %3
br label %69
51: ; preds = %37
%52 = load i32, i32* %9
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%54 = load i32, i32* %7
%55 = call i32 @pwrite(i32 %52, i8* %53, i32 1, i32 %54)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp ne i32 %56, 1
br i1 %57, label %58, label %66
58: ; preds = %51
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %8
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %60, i8* %62)
%64 = load i32, i32* %9
%65 = call i32 @close(i32 %64)
store i32 1, i32* %3
br label %69
66: ; preds = %51
%67 = load i32, i32* %9
%68 = call i32 @close(i32 %67)
store i32 0, i32* %3
br label %69
69: ; preds = %66, %58, %45
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Usage: %s <filename> <offset>(KB)\0A\00"
@.str.1 = [38 x i8] c"<offset> parameter should be integer\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.2 = [23 x i8] c"Opening %s fails (%s)\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"pwrite %s fails (%s)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = bitcast i32* %3 to i8*
store i32 2829099, i32* %3
%6 = bitcast i8** %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @strtoul(i8* %17, i8** %4, i32 10)
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %13
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %13
%27 = load i32, i32* @O_CREAT
%28 = load i32, i32* @O_RDWR
%29 = or i32 %28, %27
%30 = tail call i32 @open(i8* %15, i32 %29, i32 420)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %37
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = tail call i8* @strerror(i32 %34)
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* %35)
br label %48
37: ; preds = %26
%38 = call i32 @pwrite(i32 %30, i8* %5, i32 1, i32 %18)
%39 = icmp eq i32 %38, 1
br i1 %39, label %46, label %40
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = tail call i8* @strerror(i32 %42)
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %43)
%45 = tail call i32 @close(i32 %30)
br label %48
46: ; preds = %37
%47 = tail call i32 @close(i32 %30)
br label %48
48: ; preds = %46, %40, %32
%49 = phi i32 [ 1, %32 ], [ 1, %40 ], [ 0, %46 ]
ret i32 %49
}