#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*/ offset_file;
typedef int /*<<< orphan*/ off_t;
typedef int /*<<< orphan*/ ino_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ print_logs(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ read_offset(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ usage(char *);
scalar_t__ write_offset(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char offset_file[1024];
  char *file_name, *prog;
  ino_t inode;
  off_t offset;
  prog = argv[0];
  if (argc != 2) {
    fprintf(stderr, "no filename specified\n");
    usage(prog);
    return 1;
  }
  file_name = argv[1];
  if (strlen(".offset") + strlen(file_name) + 1 > 1024) {
    fprintf(stderr, "%s: filename too long (max is %ld)\n", prog,
            1024 - strlen(".offset") - 1);
    return 1;
  }
  strncat(offset_file, file_name,
          sizeof(offset_file) - strlen(offset_file) - 1);
  strncat(offset_file, ".offset",
          sizeof(offset_file) - strlen(offset_file) - 1);
  if (read_offset(offset_file, &inode, &offset) != 0) {
    fprintf(stderr, "%s: can't open offset file: %s\n", prog, strerror(errno));
    return 1;
  }
  if (print_logs(file_name, &inode, &offset) != 0) {
    fprintf(stderr, "%s: can't read '%s': %s\n", prog, file_name,
            strerror(errno));
    return 1;
  }
  if (write_offset(offset_file, inode, offset) != 0) {
    fprintf(stderr, "%s: can't write offset file: %s\n", prog, strerror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x420(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e0 <main+0x60>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x420(%rbp),%rdi
call   1090 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    148e <main+0x30e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x418(%rbp)
lea    0xe21(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x418(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x42c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cmp    $0x400,%eax
jle    127f <main+0xff>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    0xdce(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rdx
mov    $0x400,%ecx
sub    %eax,%ecx
sub    $0x1,%ecx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    148e <main+0x30e>
lea    -0x410(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x418(%rbp),%rax
mov    %rax,-0x450(%rbp)
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x458(%rbp),%rdi
mov    -0x450(%rbp),%rsi
movslq %eax,%rcx
mov    $0x400,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1040 <strncat@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x448(%rbp),%rdi
movslq %eax,%rcx
mov    $0x400,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
lea    0xd13(%rip),%rsi
call   1040 <strncat@plt>
lea    -0x410(%rbp),%rdi
lea    -0x424(%rbp),%rsi
lea    -0x428(%rbp),%rdx
call   1080 <read_offset@plt>
cmp    $0x0,%rax
je     1382 <main+0x202>
mov    0x2cac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x464(%rbp)
mov    -0x420(%rbp),%rax
mov    %rax,-0x460(%rbp)
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x464(%rbp),%edi
mov    -0x460(%rbp),%rdx
mov    %rax,%rcx
lea    0xcd4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    148e <main+0x30e>
mov    -0x418(%rbp),%rdi
lea    -0x424(%rbp),%rsi
lea    -0x428(%rbp),%rdx
call   1070 <print_logs@plt>
cmp    $0x0,%rax
je     1410 <main+0x290>
mov    0x2c33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x47c(%rbp)
mov    -0x420(%rbp),%rax
mov    %rax,-0x478(%rbp)
mov    -0x418(%rbp),%rax
mov    %rax,-0x470(%rbp)
mov    0x2c00(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x47c(%rbp),%edi
mov    -0x478(%rbp),%rdx
mov    -0x470(%rbp),%rcx
mov    %rax,%r8
lea    0xc66(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    148e <main+0x30e>
lea    -0x410(%rbp),%rdi
mov    -0x424(%rbp),%esi
mov    -0x428(%rbp),%edx
call   1050 <write_offset@plt>
cmp    $0x0,%rax
je     1487 <main+0x307>
mov    0x2ba7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48c(%rbp)
mov    -0x420(%rbp),%rax
mov    %rax,-0x488(%rbp)
mov    0x2b82(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x48c(%rbp),%edi
mov    -0x488(%rbp),%rdx
mov    %rax,%rcx
lea    0xc08(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    148e <main+0x30e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    (%rsi),%r14
cmp    $0x2,%edi
jne    11ec <main+0x6c>
mov    0x8(%rsi),%r15
lea    0xe77(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
cmp    $0x400,%eax
jl     1210 <main+0x90>
mov    0x2e21(%rip),%rax
mov    (%rax),%ebx
lea    0xe4f(%rip),%rdi
call   1030 <strlen@plt>
mov    $0x3ff,%ecx
sub    %eax,%ecx
lea    0xe44(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12dc <main+0x15c>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1090 <usage@plt>
jmp    12dc <main+0x15c>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x3ff,%ebp
mov    $0x3ff,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strncat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
lea    0xdd2(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncat@plt>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1080 <read_offset@plt>
test   %rax,%rax
je     1295 <main+0x115>
mov    0x2d73(%rip),%rax
mov    (%rax),%ebx
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdbf(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12dc <main+0x15c>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
call   1070 <print_logs@plt>
test   %rax,%rax
je     12ef <main+0x16f>
mov    0x2d2d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd99(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rdi
call   1050 <write_offset@plt>
test   %rax,%rax
je     1329 <main+0x1a9>
mov    0x2cd3(%rip),%rax
mov    (%rax),%ebx
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd58(%rip),%rsi
jmp    1284 <main+0x104>
xor    %eax,%eax
jmp    12e1 <main+0x161>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"no filename specified\0A\00"
@.str.1 = [8 x i8] c".offset\00"
@.str.2 = [36 x i8] c"%s: filename too long (max is %ld)\0A\00"
@.str.3 = [32 x i8] c"%s: can't open offset file: %s\0A\00"
@errno = global i32 0
@.str.4 = [25 x i8] c"%s: can't read '%s': %s\0A\00"
@.str.5 = [33 x i8] c"%s: can't write offset file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
store i8* %13, i8** %8
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %8
%20 = call i32 @usage(i8* %19)
store i32 1, i32* %3
br label %89
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %7
%25 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%26 = load i8*, i8** %7
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %25, %27
%29 = add nsw i32 %28, 1
%30 = icmp sgt i32 %29, 1024
br i1 %30, label %31, label %38
31: ; preds = %21
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %8
%34 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%35 = sub nsw i32 1024, %34
%36 = sub nsw i32 %35, 1
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %36)
store i32 1, i32* %3
br label %89
38: ; preds = %21
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%40 = load i8*, i8** %7
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
%44 = sub i64 1024, %43
%45 = sub i64 %44, 1
%46 = trunc i64 %45 to i32
%47 = call i32 @strncat(i8* %39, i8* %40, i32 %46)
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = sext i32 %50 to i64
%52 = sub i64 1024, %51
%53 = sub i64 %52, 1
%54 = trunc i64 %53 to i32
%55 = call i32 @strncat(i8* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%57 = call i64 @read_offset(i8* %56, i32* %9, i32* %10)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %38
%60 = load i32, i32* @stderr
%61 = load i8*, i8** %8
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %61, i8* %63)
store i32 1, i32* %3
br label %89
65: ; preds = %38
%66 = load i8*, i8** %7
%67 = call i64 @print_logs(i8* %66, i32* %9, i32* %10)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %65
%70 = load i32, i32* @stderr
%71 = load i8*, i8** %8
%72 = load i8*, i8** %7
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %71, i8* %72, i8* %74)
store i32 1, i32* %3
br label %89
76: ; preds = %65
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%78 = load i32, i32* %9
%79 = load i32, i32* %10
%80 = call i64 @write_offset(i8* %77, i32 %78, i32 %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %88
82: ; preds = %76
%83 = load i32, i32* @stderr
%84 = load i8*, i8** %8
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %84, i8* %86)
store i32 1, i32* %3
br label %89
88: ; preds = %76
store i32 0, i32* %3
br label %89
89: ; preds = %88, %82, %69, %59, %31, %16
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"no filename specified\0A\00"
@.str.1 = [8 x i8] c".offset\00"
@.str.2 = [36 x i8] c"%s: filename too long (max is %ld)\0A\00"
@.str.3 = [32 x i8] c"%s: can't open offset file: %s\0A\00"
@errno = global i32 0
@.str.4 = [25 x i8] c"%s: can't read '%s': %s\0A\00"
@.str.5 = [33 x i8] c"%s: can't write offset file: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i8*, i8** %1
%10 = icmp eq i32 %0, 2
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @usage(i8* %9)
br label %59
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @strlen(i8* %17)
%20 = add nsw i32 %19, %18
%21 = icmp sgt i32 %20, 1023
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%25 = sub i32 1023, %24
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %9, i32 %25)
br label %59
27: ; preds = %15
%28 = call i32 @strlen(i8* %6)
%29 = sub i32 1023, %28
%30 = call i32 @strncat(i8* %6, i8* %17, i32 %29)
%31 = call i32 @strlen(i8* %6)
%32 = sub i32 1023, %31
%33 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i64 @read_offset(i8* %6, i32* %4, i32* %5)
%35 = icmp eq i64 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %27
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %9, i8* %39)
br label %59
41: ; preds = %27
%42 = call i64 @print_logs(i8* %17, i32* %4, i32* %5)
%43 = icmp eq i64 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %9, i8* %17, i8* %47)
br label %59
49: ; preds = %41
%50 = load i32, i32* %4
%51 = load i32, i32* %5
%52 = call i64 @write_offset(i8* %6, i32 %50, i32 %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %59, label %54
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %9, i8* %57)
br label %59
59: ; preds = %49, %54, %44, %36, %22, %11
%60 = phi i32 [ 1, %11 ], [ 1, %22 ], [ 1, %36 ], [ 1, %44 ], [ 1, %54 ], [ 0, %49 ]
ret i32 %60
}