#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 */
struct timespec {
  scalar_t__ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
struct stat {
  int /*<<< orphan*/ st_mtime;
  int /*<<< orphan*/ st_atime;
};

/* Variables and functions */
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ futimens(int, struct timespec *);
int open(char const *, int);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char const *argv[]) {
  int fd;
  struct stat buf;
  struct timespec times[2];
  for (int i = 1; i < argc; ++i) {
    if (stat(argv[i], &buf) < 0) {
      fprintf(stderr, "stat error for %s\n", argv[i]);
      continue;
    }
    if ((fd = open(argv[i], O_RDWR | O_TRUNC)) < 0) {
      fprintf(stderr, "open error for %s\n", argv[i]);
      continue;
    }
    times[0].tv_sec = buf.st_atime;
    times[0].tv_nsec = 0;
    times[1].tv_sec = buf.st_mtime;
    times[1].tv_nsec = 0;
    if (futimens(fd, times) < 0) {
      fprintf(stderr, "futimens error for %s\n", argv[i]);
    }
    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   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127c <main+0x12c>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11be <main+0x6e>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe4c(%rip),%rsi
call   1040 <fprintf@plt>
jmp    126e <main+0x11e>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    0x2e1e(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1213 <main+0xc3>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe0a(%rip),%rsi
call   1040 <fprintf@plt>
jmp    126e <main+0x11e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1070 <futimens@plt>
cmp    $0x0,%rax
jge    1266 <main+0x116>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdc5(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    116d <main+0x1d>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x2,%edi
jl     1269 <main+0x119>
mov    %rsi,%rbx
mov    %edi,%r12d
mov    $0x1,%r15d
lea    0x8(%rsp),%r14
mov    0x2e51(%rip),%r13
jmp    11a4 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <close@plt>
add    $0x1,%r15
cmp    %r15,%r12
je     1269 <main+0x119>
mov    (%rbx,%r15,8),%rdi
mov    %r14,%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     1230 <main+0xe0>
mov    (%rbx,%r15,8),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
mov    0x2e17(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     1250 <main+0x100>
mov    %eax,%ebp
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
mov    %ecx,0x18(%rsp)
movq   $0x0,0x10(%rsp)
mov    %eax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
mov    %ebp,%edi
lea    0x10(%rsp),%rsi
call   1070 <futimens@plt>
test   %rax,%rax
jns    1190 <main+0x40>
mov    0x0(%r13),%edi
mov    (%rbx,%r15,8),%rdx
lea    0xe0e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1190 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%edi
mov    (%rbx,%r15,8),%rdx
lea    0xdc1(%rip),%rsi
jmp    125f <main+0x10f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    (%rbx,%r15,8),%rdx
lea    0xdb4(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1197 <main+0x47>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
%struct.timespec = type { i64, i32 }
@stderr = global i32 0
@.str = [19 x i8] c"stat error for %s\0A\00"
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [19 x i8] c"open error for %s\0A\00"
@.str.2 = [23 x i8] c"futimens error for %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca [2 x %struct.timespec]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
br label %10
10: ; preds = %77, %2
%11 = load i32, i32* %9
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %80
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i64 @stat(i8* %19, %struct.stat* %7)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %14
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %77
30: ; preds = %14
%31 = load i8**, i8*** %5
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = load i32, i32* @O_RDWR
%37 = load i32, i32* @O_TRUNC
%38 = or i32 %36, %37
%39 = call i32 @open(i8* %35, i32 %38)
store i32 %39, i32* %6
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %30
%42 = load i32, i32* @stderr
%43 = load i8**, i8*** %5
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %47)
br label %77
49: ; preds = %30
%50 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %8, i64 0, i64 0
%53 = getelementptr inbounds %struct.timespec, %struct.timespec* %52, i32 0, i32 1
store i32 %51, i32* %53
%54 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %8, i64 0, i64 0
%55 = getelementptr inbounds %struct.timespec, %struct.timespec* %54, i32 0, i32 0
store i64 0, i64* %55
%56 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%57 = load i32, i32* %56
%58 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %8, i64 0, i64 1
%59 = getelementptr inbounds %struct.timespec, %struct.timespec* %58, i32 0, i32 1
store i32 %57, i32* %59
%60 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %8, i64 0, i64 1
%61 = getelementptr inbounds %struct.timespec, %struct.timespec* %60, i32 0, i32 0
store i64 0, i64* %61
%62 = load i32, i32* %6
%63 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %8, i64 0, i64 0
%64 = call i64 @futimens(i32 %62, %struct.timespec* %63)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %49
%67 = load i32, i32* @stderr
%68 = load i8**, i8*** %5
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %66, %49
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
br label %77
77: ; preds = %74, %41, %22
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
store i32 %79, i32* %9
br label %10
80: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
%struct.timespec = type { i64, i32 }
@stderr = global i32 0
@.str = [19 x i8] c"stat error for %s\0A\00"
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [19 x i8] c"open error for %s\0A\00"
@.str.2 = [23 x i8] c"futimens error for %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca [2 x %struct.timespec]
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast [2 x %struct.timespec]* %4 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%10 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%11 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0, i32 1
%12 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0, i32 0
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 1, i32 1
%15 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 1, i32 0
%16 = zext i32 %0 to i64
br label %18
17: ; preds = %50, %2
ret i32 0
18: ; preds = %8, %50
%19 = phi i64 [ 1, %8 ], [ %51, %50 ]
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = call i64 @stat(i8* %21, %struct.stat* %3)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %20
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %50
28: ; preds = %18
%29 = load i8*, i8** %20
%30 = load i32, i32* @O_RDWR
%31 = load i32, i32* @O_TRUNC
%32 = or i32 %31, %30
%33 = call i32 @open(i8* %29, i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %20
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %50
39: ; preds = %28
%40 = load i32, i32* %9
store i32 %40, i32* %11
store i64 0, i64* %12
%41 = load i32, i32* %13
store i32 %41, i32* %14
store i64 0, i64* %15
%42 = call i64 @futimens(i32 %33, %struct.timespec* %10)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %20
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %44, %39
%49 = call i32 @close(i32 %33)
br label %50
50: ; preds = %48, %35, %24
%51 = add nuw nsw i64 %19, 1
%52 = icmp eq i64 %51, %16
br i1 %52, label %17, label %18
}