#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 /*<<< orphan*/ ERROR(int, char *);
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INT_MAX;
int O_DIRECTORY;
int O_RDONLY;
int /*<<< orphan*/ STDIN_FILENO;
int S_IRUSR;
int S_IWUSR;
int atoi(int /*<<< orphan*/);
int copy(int /*<<< orphan*/, int);
int creat(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *, ...);
int floor(int /*<<< orphan*/);
scalar_t__ fsync(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ log10(int /*<<< orphan*/);
char *malloc(int);
int open(char *, int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
int main(int argc, char *argv[]) {
  int result;
  int process_id = 0;
  int task_id = 0;
  int opt;
  while ((opt = getopt(argc, argv, "p:t:")) != -1) {
    switch (opt) {
    case 'p':
      process_id = atoi(optarg);
      if (process_id <= 0)
        error(EXIT_FAILURE, 0, "Invalid process id.");
      break;
    case 't':
      task_id = atoi(optarg);
      if (task_id <= 0)
        error(EXIT_FAILURE, 0, "Invalid task id.");
      break;
    default:
      error(EXIT_FAILURE, 0,
            "Usage: state -p process_id -t task_id -b buffer_size.");
    }
  }
  if (process_id <= 0)
    error(EXIT_FAILURE, 0, "Process id undefined.");
  if (task_id <= 0)
    error(EXIT_FAILURE, 0, "Task id undefined.");
  int int_length = floor(log10(INT_MAX)) + 1;
  int max_filename = int_length * 2 + 7 + 1;
  char *filename = malloc(max_filename);
  if (filename == NULL)
    error(EXIT_FAILURE, errno, "Can not allocate memory for state file name.");
  snprintf(filename, max_filename, "%d-%d.state", process_id, task_id);
  int state_fd = creat(filename, S_IRUSR | S_IWUSR);
  if (state_fd < 0)
    error(EXIT_FAILURE, errno, "Can not open state file '#%s' for writing.",
          filename);
  result = copy(STDIN_FILENO, state_fd);
  if (result < 0)
    ERROR(1, "Can not copy data.");
  if (fsync(state_fd) < 0)
    error(EXIT_FAILURE, errno, "Can not sync file.");
  int dir_fd = open(".", O_DIRECTORY | O_RDONLY);
  if (dir_fd < 0)
    error(EXIT_FAILURE, errno, "Can not open directory.");
  if (fsync(dir_fd) < 0)
    error(EXIT_FAILURE, errno, "Can not sync directory.");
  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)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe0e(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     12b8 <main+0xf8>
mov    -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x70,%eax
je     1228 <main+0x68>
jmp    1217 <main+0x57>
mov    -0x3c(%rbp),%eax
sub    $0x74,%eax
je     1261 <main+0xa1>
jmp    129a <main+0xda>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   10c0 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     125c <main+0x9c>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
lea    0xdb0(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
jmp    12b3 <main+0xf3>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   10c0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1295 <main+0xd5>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
lea    0xd8b(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
jmp    12b3 <main+0xf3>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
lea    0xd7e(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
jmp    11e4 <main+0x24>
cmpl   $0x0,-0x18(%rbp)
jg     12db <main+0x11b>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
lea    0xd8c(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
cmpl   $0x0,-0x1c(%rbp)
jg     12fe <main+0x13e>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
lea    0xd7f(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   10b0 <log10@plt>
mov    %eax,%edi
call   10e0 <floor@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
add    $0x7,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    135f <main+0x19f>
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
mov    0x2c69(%rip),%rax
mov    (%rax),%esi
lea    0xd31(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xd42(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2c24(%rip),%rax
mov    (%rax),%esi
mov    0x2c43(%rip),%rax
or     (%rax),%esi
call   10d0 <creat@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    13c5 <main+0x205>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
mov    0x2c07(%rip),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rcx
lea    0xd04(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%esi
call   1040 <copy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    13f4 <main+0x234>
mov    $0x1,%edi
lea    0xcfe(%rip),%rsi
call   1090 <ERROR@plt>
mov    -0x34(%rbp),%edi
call   1070 <fsync@plt>
cmp    $0x0,%rax
jge    1426 <main+0x266>
mov    0x2ba3(%rip),%rax
mov    (%rax),%edi
mov    0x2ba2(%rip),%rax
mov    (%rax),%esi
lea    0xce1(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
mov    0x2b93(%rip),%rax
mov    (%rax),%esi
mov    0x2baa(%rip),%rax
or     (%rax),%esi
lea    0xcbf(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    1471 <main+0x2b1>
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
mov    0x2b57(%rip),%rax
mov    (%rax),%esi
lea    0xca9(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
mov    -0x38(%rbp),%edi
call   1070 <fsync@plt>
cmp    $0x0,%rax
jge    14a3 <main+0x2e3>
mov    0x2b26(%rip),%rax
mov    (%rax),%edi
mov    0x2b25(%rip),%rax
mov    (%rax),%esi
lea    0xc8f(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
xor    %eax,%eax
add    $0x40,%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,%r15
mov    %edi,%ebx
lea    0xe29(%rip),%r12
mov    0x2e1a(%rip),%r13
xor    %r14d,%r14d
xor    %ebp,%ebp
jmp    1200 <main+0x40>
lea    0xe3e(%rip),%rdx
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <error@plt>
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   10a0 <getopt@plt>
cmp    $0x70,%eax
jne    122a <main+0x6a>
mov    0x0(%r13),%edi
call   10c0 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1200 <main+0x40>
lea    0xddd(%rip),%rdx
jmp    11ec <main+0x2c>
cmp    $0xffffffff,%eax
je     124d <main+0x8d>
cmp    $0x74,%eax
jne    11e5 <main+0x25>
mov    0x0(%r13),%edi
call   10c0 <atoi@plt>
mov    %eax,%r14d
lea    0xdd2(%rip),%rdx
test   %eax,%eax
jg     1200 <main+0x40>
jmp    11ec <main+0x2c>
test   %ebp,%ebp
jle    13d3 <main+0x213>
test   %r14d,%r14d
jle    13f5 <main+0x235>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   10b0 <log10@plt>
mov    %eax,%edi
call   10e0 <floor@plt>
lea    (%rax,%rax,1),%ebx
add    $0xa,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    12a8 <main+0xe8>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    0x2d20(%rip),%rax
mov    (%rax),%esi
lea    0xde8(%rip),%rdx
xor    %eax,%eax
call   1060 <error@plt>
lea    0xe07(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%ecx
mov    %r14d,%r8d
call   1030 <snprintf@plt>
mov    0x2ce3(%rip),%rax
mov    0x2d04(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r15,%rdi
call   10d0 <creat@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1301 <main+0x141>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
mov    0x2cca(%rip),%rax
mov    (%rax),%esi
lea    0xdcb(%rip),%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <error@plt>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%esi
call   1040 <copy@plt>
test   %eax,%eax
jns    1326 <main+0x166>
lea    0xdd1(%rip),%rsi
mov    $0x1,%edi
call   1090 <ERROR@plt>
mov    %ebp,%edi
call   1070 <fsync@plt>
test   %rax,%rax
jns    1352 <main+0x192>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
mov    0x2c76(%rip),%rax
mov    (%rax),%esi
lea    0xdb5(%rip),%rdx
xor    %eax,%eax
call   1060 <error@plt>
mov    0x2c67(%rip),%rax
mov    0x2c80(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xd93(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1396 <main+0x1d6>
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
mov    0x2c32(%rip),%rax
mov    (%rax),%esi
lea    0xd84(%rip),%rdx
xor    %eax,%eax
call   1060 <error@plt>
mov    %ebx,%edi
call   1070 <fsync@plt>
test   %rax,%rax
jns    13c2 <main+0x202>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
mov    0x2c06(%rip),%rax
mov    (%rax),%esi
lea    0xd70(%rip),%rdx
xor    %eax,%eax
call   1060 <error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
lea    0xc7d(%rip),%rdx
xor    %esi,%esi
xor    %eax,%eax
call   1060 <error@plt>
test   %r14d,%r14d
jg     125e <main+0x9e>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
lea    0xc71(%rip),%rdx
xor    %esi,%esi
xor    %eax,%eax
call   1060 <error@plt>
jmp    125e <main+0x9e>

LLVM IR (-O0):
@.str = [5 x i8] c"p:t:\00"
@optarg = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"Invalid process id.\00"
@.str.2 = [17 x i8] c"Invalid task id.\00"
@.str.3 = [54 x i8] c"Usage: state -p process_id -t task_id -b buffer_size.\00"
@.str.4 = [22 x i8] c"Process id undefined.\00"
@.str.5 = [19 x i8] c"Task id undefined.\00"
@INT_MAX = global i32 0
@errno = global i32 0
@.str.6 = [45 x i8] c"Can not allocate memory for state file name.\00"
@.str.7 = [12 x i8] c"%d-%d.state\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.8 = [43 x i8] c"Can not open state file '#%s' for writing.\00"
@STDIN_FILENO = global i32 0
@.str.9 = [19 x i8] c"Can not copy data.\00"
@.str.10 = [19 x i8] c"Can not sync file.\00"
@.str.11 = [2 x i8] c".\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@.str.12 = [24 x i8] c"Can not open directory.\00"
@.str.13 = [24 x i8] c"Can not sync directory.\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*
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
br label %15
15: ; preds = %43, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %9
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %44
20: ; preds = %15
%21 = load i32, i32* %9
switch i32 %21, label %40 [
i32 112, label %22
i32 116, label %31
]
22: ; preds = %20
%23 = load i32, i32* @optarg
%24 = call i32 @atoi(i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 (i32, i32, i8*, ...) @error(i32 %28, i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %27, %22
br label %43
31: ; preds = %20
%32 = load i32, i32* @optarg
%33 = call i32 @atoi(i32 %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp sle i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 (i32, i32, i8*, ...) @error(i32 %37, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %36, %31
br label %43
40: ; preds = %20
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 (i32, i32, i8*, ...) @error(i32 %41, i32 0, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %40, %39, %30
br label %15
44: ; preds = %15
%45 = load i32, i32* %7
%46 = icmp sle i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 (i32, i32, i8*, ...) @error(i32 %48, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %47, %44
%51 = load i32, i32* %8
%52 = icmp sle i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 (i32, i32, i8*, ...) @error(i32 %54, i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %53, %50
%57 = load i32, i32* @INT_MAX
%58 = call i32 @log10(i32 %57)
%59 = call i32 @floor(i32 %58)
%60 = add nsw i32 %59, 1
store i32 %60, i32* %10
%61 = load i32, i32* %10
%62 = mul nsw i32 %61, 2
%63 = add nsw i32 %62, 7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %11
%65 = load i32, i32* %11
%66 = call i8* @malloc(i32 %65)
store i8* %66, i8** %12
%67 = load i8*, i8** %12
%68 = icmp eq i8* %67, null
br i1 %68, label %69, label %73
69: ; preds = %56
%70 = load i32, i32* @EXIT_FAILURE
%71 = load i32, i32* @errno
%72 = call i32 (i32, i32, i8*, ...) @error(i32 %70, i32 %71, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
br label %73
73: ; preds = %69, %56
%74 = load i8*, i8** %12
%75 = load i32, i32* %11
%76 = load i32, i32* %7
%77 = load i32, i32* %8
%78 = call i32 @snprintf(i8* %74, i32 %75, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %76, i32 %77)
%79 = load i8*, i8** %12
%80 = load i32, i32* @S_IRUSR
%81 = load i32, i32* @S_IWUSR
%82 = or i32 %80, %81
%83 = call i32 @creat(i8* %79, i32 %82)
store i32 %83, i32* %13
%84 = load i32, i32* %13
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %73
%87 = load i32, i32* @EXIT_FAILURE
%88 = load i32, i32* @errno
%89 = load i8*, i8** %12
%90 = call i32 (i32, i32, i8*, ...) @error(i32 %87, i32 %88, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* %89)
br label %91
91: ; preds = %86, %73
%92 = load i32, i32* @STDIN_FILENO
%93 = load i32, i32* %13
%94 = call i32 @copy(i32 %92, i32 %93)
store i32 %94, i32* %6
%95 = load i32, i32* %6
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %91
%98 = call i32 @ERROR(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %99
99: ; preds = %97, %91
%100 = load i32, i32* %13
%101 = call i64 @fsync(i32 %100)
%102 = icmp slt i64 %101, 0
br i1 %102, label %103, label %107
103: ; preds = %99
%104 = load i32, i32* @EXIT_FAILURE
%105 = load i32, i32* @errno
%106 = call i32 (i32, i32, i8*, ...) @error(i32 %104, i32 %105, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %107
107: ; preds = %103, %99
%108 = load i32, i32* @O_DIRECTORY
%109 = load i32, i32* @O_RDONLY
%110 = or i32 %108, %109
%111 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32 %110)
store i32 %111, i32* %14
%112 = load i32, i32* %14
%113 = icmp slt i32 %112, 0
br i1 %113, label %114, label %118
114: ; preds = %107
%115 = load i32, i32* @EXIT_FAILURE
%116 = load i32, i32* @errno
%117 = call i32 (i32, i32, i8*, ...) @error(i32 %115, i32 %116, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
br label %118
118: ; preds = %114, %107
%119 = load i32, i32* %14
%120 = call i64 @fsync(i32 %119)
%121 = icmp slt i64 %120, 0
br i1 %121, label %122, label %126
122: ; preds = %118
%123 = load i32, i32* @EXIT_FAILURE
%124 = load i32, i32* @errno
%125 = call i32 (i32, i32, i8*, ...) @error(i32 %123, i32 %124, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0))
br label %126
126: ; preds = %122, %118
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"p:t:\00"
@optarg = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"Invalid process id.\00"
@.str.2 = [17 x i8] c"Invalid task id.\00"
@.str.3 = [54 x i8] c"Usage: state -p process_id -t task_id -b buffer_size.\00"
@.str.4 = [22 x i8] c"Process id undefined.\00"
@.str.5 = [19 x i8] c"Task id undefined.\00"
@INT_MAX = global i32 0
@errno = global i32 0
@.str.6 = [45 x i8] c"Can not allocate memory for state file name.\00"
@.str.7 = [12 x i8] c"%d-%d.state\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.8 = [43 x i8] c"Can not open state file '#%s' for writing.\00"
@STDIN_FILENO = global i32 0
@.str.9 = [19 x i8] c"Can not copy data.\00"
@.str.10 = [19 x i8] c"Can not sync file.\00"
@.str.11 = [2 x i8] c".\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@.str.12 = [24 x i8] c"Can not open directory.\00"
@.str.13 = [24 x i8] c"Can not sync directory.\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %17, %2
%4 = phi i32 [ 0, %2 ], [ %18, %17 ]
%5 = phi i32 [ 0, %2 ], [ %19, %17 ]
br label %6
6: ; preds = %3, %9
%7 = phi i32 [ %11, %9 ], [ %5, %3 ]
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %20 [
i32 -1, label %26
i32 112, label %9
i32 116, label %13
]
9: ; preds = %6
%10 = load i32, i32* @optarg
%11 = tail call i32 @atoi(i32 %10)
%12 = icmp slt i32 %11, 1
br i1 %12, label %20, label %6
13: ; preds = %6
%14 = load i32, i32* @optarg
%15 = tail call i32 @atoi(i32 %14)
%16 = icmp slt i32 %15, 1
br i1 %16, label %20, label %17
17: ; preds = %13, %20
%18 = phi i32 [ %22, %20 ], [ %15, %13 ]
%19 = phi i32 [ %23, %20 ], [ %7, %13 ]
br label %3
20: ; preds = %6, %9, %13
%21 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), %6 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %9 ]
%22 = phi i32 [ %15, %13 ], [ %4, %9 ], [ %4, %6 ]
%23 = phi i32 [ %7, %13 ], [ %7, %6 ], [ %11, %9 ]
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 (i32, i32, i8*, ...) @error(i32 %24, i32 0, i8* %21)
br label %17
26: ; preds = %6
%27 = icmp slt i32 %7, 1
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 (i32, i32, i8*, ...) @error(i32 %29, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %28, %26
%32 = icmp slt i32 %4, 1
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 (i32, i32, i8*, ...) @error(i32 %34, i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %36
36: ; preds = %33, %31
%37 = load i32, i32* @INT_MAX
%38 = tail call i32 @log10(i32 %37)
%39 = tail call i32 @floor(i32 %38)
%40 = shl i32 %39, 1
%41 = add i32 %40, 10
%42 = tail call i8* @malloc(i32 %41)
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %36
%45 = load i32, i32* @EXIT_FAILURE
%46 = load i32, i32* @errno
%47 = tail call i32 (i32, i32, i8*, ...) @error(i32 %45, i32 %46, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %44, %36
%49 = tail call i32 @snprintf(i8* %42, i32 %41, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %7, i32 %4)
%50 = load i32, i32* @S_IRUSR
%51 = load i32, i32* @S_IWUSR
%52 = or i32 %51, %50
%53 = tail call i32 @creat(i8* %42, i32 %52)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %48
%56 = load i32, i32* @EXIT_FAILURE
%57 = load i32, i32* @errno
%58 = tail call i32 (i32, i32, i8*, ...) @error(i32 %56, i32 %57, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* %42)
br label %59
59: ; preds = %55, %48
%60 = load i32, i32* @STDIN_FILENO
%61 = tail call i32 @copy(i32 %60, i32 %53)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = tail call i32 @ERROR(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
%66 = tail call i64 @fsync(i32 %53)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = load i32, i32* @EXIT_FAILURE
%70 = load i32, i32* @errno
%71 = tail call i32 (i32, i32, i8*, ...) @error(i32 %69, i32 %70, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %72
72: ; preds = %68, %65
%73 = load i32, i32* @O_DIRECTORY
%74 = load i32, i32* @O_RDONLY
%75 = or i32 %74, %73
%76 = tail call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32 %75)
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %72
%79 = load i32, i32* @EXIT_FAILURE
%80 = load i32, i32* @errno
%81 = tail call i32 (i32, i32, i8*, ...) @error(i32 %79, i32 %80, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
br label %82
82: ; preds = %78, %72
%83 = tail call i64 @fsync(i32 %76)
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %89
85: ; preds = %82
%86 = load i32, i32* @EXIT_FAILURE
%87 = load i32, i32* @errno
%88 = tail call i32 (i32, i32, i8*, ...) @error(i32 %86, i32 %87, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0))
br label %89
89: ; preds = %85, %82
ret i32 0
}