#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct stat {
  scalar_t__ st_ino;
  scalar_t__ st_mtime;
  scalar_t__ st_atime;
  scalar_t__ st_size;
};

/* Variables and functions */
int O_CREAT;
int O_EXCL;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long long, long, long, long);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ unlink(char *);
scalar_t__ utimes(char *, struct timeval *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd = open("/tmp/foo", O_CREAT | O_WRONLY | O_EXCL, 0666);
  struct timeval tv[2];
  struct stat s;
  if (fd == -1) {
    perror("open");
    return -1;
  }
  lseek(fd, 0x100000000, SEEK_SET);
  write(fd, "x", 1);
  close(fd);
  tv[0].tv_sec = 123456789;
  tv[0].tv_usec = 0;
  tv[1].tv_sec = 123456789;
  tv[1].tv_usec = 0;
  if (utimes("/tmp/foo", tv)) {
    perror("utimes");
    unlink("/tmp/foo");
    return -1;
  }
  if (stat("/tmp/foo", &s)) {
    perror("stat");
    unlink("/tmp/foo");
    return -1;
  }
  printf("size %lld, atime %ld, mtime %ld, inode %ld\n", (long long)s.st_size,
         (long)s.st_atime, (long)s.st_mtime, (long)s.st_ino);
  unlink("/tmp/foo");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2e11(%rip),%rax
or     (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
lea    0xe3f(%rip),%rdi
mov    $0x1b6,%edx
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11f0 <main+0x60>
lea    0xe2a(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x151>
mov    -0x8(%rbp),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    0xe01(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0x75bcd15,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x75bcd15,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xdb8(%rip),%rdi
call   1080 <utimes@plt>
cmp    $0x0,%rax
je     127b <main+0xeb>
lea    0xdb2(%rip),%rdi
call   10b0 <perror@plt>
lea    0xd96(%rip),%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x151>
lea    0xd7e(%rip),%rdi
lea    -0x50(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
je     12b9 <main+0x129>
lea    0xd7b(%rip),%rdi
call   10b0 <perror@plt>
lea    0xd58(%rip),%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <main+0x151>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
lea    0xd4c(%rip),%rdi
call   1050 <printf@plt>
lea    0xd24(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    0x2e5c(%rip),%rax
mov    0x2e1d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e2a(%rip),%rax
or     (%rax),%esi
lea    0xe49(%rip),%rdi
mov    $0x1b6,%edx
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     1277 <main+0xe7>
mov    %eax,%ebx
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
lea    0xe29(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1070 <close@plt>
movl   $0x75bcd15,(%rsp)
movq   $0x0,0x8(%rsp)
movl   $0x75bcd15,0x10(%rsp)
07
movq   $0x0,0x18(%rsp)
lea    0xde0(%rip),%rdi
mov    %rsp,%rsi
call   1080 <utimes@plt>
test   %rax,%rax
jne    128a <main+0xfa>
lea    0xdcc(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1090 <stat@plt>
test   %rax,%rax
jne    1293 <main+0x103>
mov    0x38(%rsp),%rsi
mov    0x30(%rsp),%rdx
mov    0x20(%rsp),%r8
mov    0x28(%rsp),%rcx
lea    0xdbe(%rip),%rdi
call   1050 <printf@plt>
lea    0xd96(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret
lea    0xd8b(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
jmp    1271 <main+0xe1>
lea    0xd7f(%rip),%rdi
jmp    129a <main+0x10a>
lea    0xd7d(%rip),%rdi
call   10b0 <perror@plt>
lea    0xd5a(%rip),%rdi
call   1030 <unlink@plt>
mov    $0xffffffff,%eax
jmp    1271 <main+0xe1>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.stat = type { i64, i64, i64, i64 }
@.str = [9 x i8] c"/tmp/foo\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_EXCL = global i32 0
@.str.1 = [5 x i8] c"open\00"
@SEEK_SET = global i32 0
@.str.2 = [2 x i8] c"x\00"
@.str.3 = [7 x i8] c"utimes\00"
@.str.4 = [5 x i8] c"stat\00"
@.str.5 = [44 x i8] c"size %lld, atime %ld, mtime %ld, inode %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x %struct.timeval]
%4 = alloca %struct.stat
store i32 0, i32* %1
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_WRONLY
%7 = or i32 %5, %6
%8 = load i32, i32* @O_EXCL
%9 = or i32 %7, %8
%10 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9, i32 438)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %54
15: ; preds = %0
%16 = load i32, i32* %2
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @lseek(i32 %16, i32 0, i32 %17)
%19 = load i32, i32* %2
%20 = call i32 @write(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
%23 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 0
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %23, i32 0, i32 0
store i32 123456789, i32* %24
%25 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 0
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 1
store i64 0, i64* %26
%27 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 1
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 0
store i32 123456789, i32* %28
%29 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 1
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 1
store i64 0, i64* %30
%31 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 0
%32 = call i64 @utimes(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.timeval* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %15
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %54
37: ; preds = %15
%38 = call i64 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %4)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %54
43: ; preds = %37
%44 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 3
%45 = load i64, i64* %44
%46 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 2
%47 = load i64, i64* %46
%48 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%49 = load i64, i64* %48
%50 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%51 = load i64, i64* %50
%52 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i64 %45, i64 %47, i64 %49, i64 %51)
%53 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %54
54: ; preds = %43, %40, %34, %13
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.stat = type { i64, i64, i64, i64 }
@.str = [9 x i8] c"/tmp/foo\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_EXCL = global i32 0
@.str.1 = [5 x i8] c"open\00"
@SEEK_SET = global i32 0
@.str.2 = [2 x i8] c"x\00"
@.str.3 = [7 x i8] c"utimes\00"
@.str.4 = [5 x i8] c"stat\00"
@.str.5 = [44 x i8] c"size %lld, atime %ld, mtime %ld, inode %ld\0A\00"
define i32 @main() {
%1 = alloca [2 x %struct.timeval]
%2 = alloca %struct.stat
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_WRONLY
%5 = or i32 %4, %3
%6 = load i32, i32* @O_EXCL
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7, i32 438)
%9 = bitcast [2 x %struct.timeval]* %1 to i8*
%10 = bitcast %struct.stat* %2 to i8*
%11 = icmp eq i32 %8, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %46
14: ; preds = %0
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @lseek(i32 %8, i32 0, i32 %15)
%17 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%18 = tail call i32 @close(i32 %8)
%19 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %1, i64 0, i64 0
%20 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %1, i64 0, i64 0, i32 0
store i32 123456789, i32* %20
%21 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %1, i64 0, i64 0, i32 1
store i64 0, i64* %21
%22 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %1, i64 0, i64 1, i32 0
store i32 123456789, i32* %22
%23 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %1, i64 0, i64 1, i32 1
store i64 0, i64* %23
%24 = call i64 @utimes(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.timeval* %19)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %14
%27 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%28 = tail call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %46
29: ; preds = %14
%30 = call i64 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %46
35: ; preds = %29
%36 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 3
%37 = load i64, i64* %36
%38 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 2
%39 = load i64, i64* %38
%40 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%41 = load i64, i64* %40
%42 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%43 = load i64, i64* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i64 %37, i64 %39, i64 %41, i64 %43)
%45 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %46
46: ; preds = %35, %32, %26, %12
%47 = phi i32 [ -1, %12 ], [ -1, %26 ], [ -1, %32 ], [ 0, %35 ]
ret i32 %47
}