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

/* Variables and functions */
int EOF;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ _err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int ftruncate64(int, int /*<<< orphan*/);
int get_number(int /*<<< orphan*/, int /*<<< orphan*/ *);
int getopt(int, char **, char *);
int open64(char *, int, int);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ print_usage();
int pwrite64(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  uint64_t trunc_to = 0, write_at = 0;
  int c, ret, fd;
  int trunc = 0;
  char *filename;
  while ((c = getopt(argc, argv, "t:w:")) != EOF) {
    switch (c) {
    case 't':
      ret = get_number(optarg, &trunc_to);
      if (ret) {
        print_usage();
        return 1;
      }
      trunc = 1;
      break;
    case 'w':
      ret = get_number(optarg, &write_at);
      if (ret) {
        print_usage();
        return 1;
      }
      break;
    default:
      print_usage();
      return 1;
      break;
    }
  }
  if (optind >= argc) {
    print_usage();
    return 1;
  }
  filename = argv[optind];
  fd = open64(filename, O_RDWR | O_CREAT, 0644);
  if (fd < 0) {
    _err(errno, "During open");
    return 1;
  }
  if (trunc) {
    ret = ftruncate64(fd, trunc_to);
    if (ret < 0) {
      _err(errno, "During truncate");
      return 1;
    }
  }
  ret = pwrite64(fd, filename, strlen(filename), write_at);
  if (ret < 0) {
    _err(errno, "During pwrite");
    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)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe37(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
je     1292 <main+0x102>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x74,%eax
je     1205 <main+0x75>
jmp    11f4 <main+0x64>
mov    -0x34(%rbp),%eax
sub    $0x77,%eax
je     1243 <main+0xb3>
jmp    127a <main+0xea>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
call   1060 <get_number@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1237 <main+0xa7>
mov    $0x0,%al
call   10b0 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x238>
movl   $0x1,-0x28(%rbp)
jmp    128d <main+0xfd>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1060 <get_number@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1275 <main+0xe5>
mov    $0x0,%al
call   10b0 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x238>
jmp    128d <main+0xfd>
mov    $0x0,%al
call   10b0 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x238>
jmp    11bb <main+0x2b>
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     12b7 <main+0x127>
mov    $0x0,%al
call   10b0 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x238>
mov    -0x10(%rbp),%rax
mov    0x2d06(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
mov    0x2d17(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1090 <open64@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    131b <main+0x18b>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
call   1030 <_err@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x238>
cmpl   $0x0,-0x28(%rbp)
je     1363 <main+0x1d3>
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1080 <ftruncate64@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    135e <main+0x1ce>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
lea    0xcc4(%rip),%rsi
call   1030 <_err@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x238>
jmp    1363 <main+0x1d3>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%ecx
call   1070 <pwrite64@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    13b9 <main+0x229>
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
lea    0xc79(%rip),%rsi
call   1030 <_err@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c8 <main+0x238>
mov    -0x24(%rbp),%edi
call   1050 <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   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %edi,%ebp
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0xe4a(%rip),%rdx
call   10a0 <getopt@plt>
mov    0x2e0e(%rip),%r14
xor    %ebx,%ebx
cmp    (%r14),%eax
jne    1251 <main+0xc1>
mov    0x2df4(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    12b7 <main+0x127>
mov    0x0(%r13,%rax,8),%r14
mov    0x2ded(%rip),%rax
mov    0x2e06(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1a4,%edx
call   1090 <open64@plt>
test   %eax,%eax
js     12c0 <main+0x130>
mov    %eax,%ebp
test   %ebx,%ebx
je     1224 <main+0x94>
mov    0x4(%rsp),%esi
mov    %ebp,%edi
call   1080 <ftruncate64@plt>
test   %eax,%eax
js     12e4 <main+0x154>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    (%rsp),%ecx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1070 <pwrite64@plt>
test   %eax,%eax
js     12d2 <main+0x142>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    12fe <main+0x16e>
xor    %ebx,%ebx
mov    0x2d96(%rip),%r12
lea    0xd9f(%rip),%r15
jmp    1296 <main+0x106>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edi
mov    %rsp,%rsi
call   1060 <get_number@plt>
test   %eax,%eax
jne    12b7 <main+0x127>
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    (%r14),%eax
je     11cd <main+0x3d>
cmp    $0x77,%eax
je     1270 <main+0xe0>
cmp    $0x74,%eax
jne    12b7 <main+0x127>
mov    (%r12),%edi
lea    0x4(%rsp),%rsi
call   1060 <get_number@plt>
mov    $0x1,%ebx
test   %eax,%eax
je     1280 <main+0xf0>
xor    %eax,%eax
call   10b0 <print_usage@plt>
jmp    12f9 <main+0x169>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
jmp    12f4 <main+0x164>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
lea    0xd3f(%rip),%rsi
jmp    12f4 <main+0x164>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
call   1030 <_err@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"t:w:\00"
@EOF = global i32 0
@optarg = global i32 0
@optind = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@errno = global i32 0
@.str.1 = [12 x i8] c"During open\00"
@.str.2 = [16 x i8] c"During truncate\00"
@.str.3 = [14 x i8] c"During pwrite\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %11
br label %13
13: ; preds = %39, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %8
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %40
19: ; preds = %13
%20 = load i32, i32* %8
switch i32 %20, label %37 [
i32 116, label %21
i32 119, label %29
]
21: ; preds = %19
%22 = load i32, i32* @optarg
%23 = call i32 @get_number(i32 %22, i32* %6)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 (...) @print_usage()
store i32 1, i32* %3
br label %90
28: ; preds = %21
store i32 1, i32* %11
br label %39
29: ; preds = %19
%30 = load i32, i32* @optarg
%31 = call i32 @get_number(i32 %30, i32* %7)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 (...) @print_usage()
store i32 1, i32* %3
br label %90
36: ; preds = %29
br label %39
37: ; preds = %19
%38 = call i32 (...) @print_usage()
store i32 1, i32* %3
br label %90
39: ; preds = %36, %28
br label %13
40: ; preds = %13
%41 = load i32, i32* @optind
%42 = load i32, i32* %4
%43 = icmp sge i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 (...) @print_usage()
store i32 1, i32* %3
br label %90
46: ; preds = %40
%47 = load i8**, i8*** %5
%48 = load i32, i32* @optind
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
store i8* %51, i8** %12
%52 = load i8*, i8** %12
%53 = load i32, i32* @O_RDWR
%54 = load i32, i32* @O_CREAT
%55 = or i32 %53, %54
%56 = call i32 @open64(i8* %52, i32 %55, i32 420)
store i32 %56, i32* %10
%57 = load i32, i32* %10
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %46
%60 = load i32, i32* @errno
%61 = call i32 @_err(i32 %60, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %90
62: ; preds = %46
%63 = load i32, i32* %11
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %75
65: ; preds = %62
%66 = load i32, i32* %10
%67 = load i32, i32* %6
%68 = call i32 @ftruncate64(i32 %66, i32 %67)
store i32 %68, i32* %9
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %65
%72 = load i32, i32* @errno
%73 = call i32 @_err(i32 %72, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %90
74: ; preds = %65
br label %75
75: ; preds = %74, %62
%76 = load i32, i32* %10
%77 = load i8*, i8** %12
%78 = load i8*, i8** %12
%79 = call i32 @strlen(i8* %78)
%80 = load i32, i32* %7
%81 = call i32 @pwrite64(i32 %76, i8* %77, i32 %79, i32 %80)
store i32 %81, i32* %9
%82 = load i32, i32* %9
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %75
%85 = load i32, i32* @errno
%86 = call i32 @_err(i32 %85, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %90
87: ; preds = %75
%88 = load i32, i32* %10
%89 = call i32 @close(i32 %88)
store i32 0, i32* %3
br label %90
90: ; preds = %87, %84, %71, %59, %44, %37, %34, %26
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@.str = [5 x i8] c"t:w:\00"
@EOF = global i32 0
@optarg = global i32 0
@optind = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@errno = global i32 0
@.str.1 = [12 x i8] c"During open\00"
@.str.2 = [16 x i8] c"During truncate\00"
@.str.3 = [14 x i8] c"During pwrite\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %32, label %10
10: ; preds = %2, %27
%11 = phi i32 [ %29, %27 ], [ %7, %2 ]
%12 = phi i32 [ %28, %27 ], [ 0, %2 ]
switch i32 %11, label %25 [
i32 116, label %13
i32 119, label %19
]
13: ; preds = %10
%14 = load i32, i32* @optarg
%15 = call i32 @get_number(i32 %14, i32* %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = call i32 (...) @print_usage()
br label %69
19: ; preds = %10
%20 = load i32, i32* @optarg
%21 = call i32 @get_number(i32 %20, i32* %4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = call i32 (...) @print_usage()
br label %69
25: ; preds = %10
%26 = call i32 (...) @print_usage()
br label %69
27: ; preds = %13, %19
%28 = phi i32 [ %12, %19 ], [ 1, %13 ]
%29 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %10
32: ; preds = %27, %2
%33 = phi i32 [ 0, %2 ], [ %28, %27 ]
%34 = load i32, i32* @optind
%35 = icmp slt i32 %34, %0
br i1 %35, label %38, label %36
36: ; preds = %32
%37 = call i32 (...) @print_usage()
br label %69
38: ; preds = %32
%39 = sext i32 %34 to i64
%40 = getelementptr inbounds i8*, i8** %1, i64 %39
%41 = load i8*, i8** %40
%42 = load i32, i32* @O_RDWR
%43 = load i32, i32* @O_CREAT
%44 = or i32 %43, %42
%45 = call i32 @open64(i8* %41, i32 %44, i32 420)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %38
%48 = load i32, i32* @errno
%49 = call i32 @_err(i32 %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %69
50: ; preds = %38
%51 = icmp eq i32 %33, 0
br i1 %51, label %59, label %52
52: ; preds = %50
%53 = load i32, i32* %3
%54 = call i32 @ftruncate64(i32 %45, i32 %53)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load i32, i32* @errno
%58 = call i32 @_err(i32 %57, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %69
59: ; preds = %52, %50
%60 = call i32 @strlen(i8* %41)
%61 = load i32, i32* %4
%62 = call i32 @pwrite64(i32 %45, i8* %41, i32 %60, i32 %61)
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %59
%65 = load i32, i32* @errno
%66 = call i32 @_err(i32 %65, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %69
67: ; preds = %59
%68 = call i32 @close(i32 %45)
br label %69
69: ; preds = %67, %64, %56, %47, %36, %25, %23, %17
%70 = phi i32 [ 1, %25 ], [ 1, %23 ], [ 1, %17 ], [ 1, %36 ], [ 1, %47 ], [ 1, %56 ], [ 1, %64 ], [ 0, %67 ]
ret i32 %70
}