#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 utimbuf {
  int actime;
  int modtime;
};
struct stat {
  int st_mtime;
  int st_atime;
};

/* Variables and functions */
int L_tmpnam;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ remove(char *);
scalar_t__ stat(char *, struct stat *);
scalar_t__ tmpnam(char *);
scalar_t__ utime(char *, struct utimbuf *);
int main(int argc, char *argv[]) {
  char file[L_tmpnam];
  struct utimbuf ut;
  struct stat st;
  int fd;
  if (tmpnam(file) == 0) {
    perror("tmpnam");
    exit(1);
  }
  fd = creat(file, 0666);
  if (fd < 0) {
    perror("creat");
    exit(1);
  }
  close(fd);
  ut.actime = 500000000;
  ut.modtime = 500000002;
  if (utime(file, &ut)) {
    perror("utime");
    remove(file);
    exit(1);
  }
  if (stat(file, &st)) {
    perror("stat");
    remove(file);
    exit(1);
  }
  remove(file);
  if (st.st_mtime != ut.modtime) {
    printf("modtime %ld != %ld\n", st.st_mtime, ut.modtime);
    exit(1);
  }
  if (st.st_atime != ut.actime) {
    printf("actime %ld != %ld\n", st.st_atime, ut.actime);
    exit(1);
  }
  puts("Test succeeded.");
  exit(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)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
call   10c0 <tmpnam@plt>
cmp    $0x0,%rax
jne    1207 <main+0x67>
lea    0xe08(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    $0x1b6,%esi
call   10a0 <creat@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1238 <main+0x98>
lea    0xdde(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
mov    -0x40(%rbp),%rdi
movl   $0x1dcd6500,-0x28(%rbp)
movl   $0x1dcd6502,-0x24(%rbp)
lea    -0x28(%rbp),%rsi
call   1030 <utime@plt>
cmp    $0x0,%rax
je     1284 <main+0xe4>
lea    0xda1(%rip),%rdi
call   1090 <perror@plt>
mov    -0x40(%rbp),%rdi
call   1040 <remove@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
je     12ba <main+0x11a>
lea    0xd71(%rip),%rdi
call   1090 <perror@plt>
mov    -0x40(%rbp),%rdi
call   1040 <remove@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     12eb <main+0x14b>
mov    -0x30(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd3c(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     1313 <main+0x173>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xd28(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd25(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   10c0 <tmpnam@plt>
test   %rax,%rax
jne    11d9 <main+0x39>
lea    0xe29(%rip),%rdi
jmp    11f1 <main+0x51>
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   10a0 <creat@plt>
test   %eax,%eax
jns    1200 <main+0x60>
lea    0xe16(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%edi
call   1070 <close@plt>
movabs $0x1dcd65021dcd6500,%rax
65 cd 1d
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rsi
mov    %rbx,%rdi
call   1030 <utime@plt>
test   %rax,%rax
jne    1268 <main+0xc8>
lea    -0x10(%rbp),%rsi
mov    %rbx,%rdi
call   1080 <stat@plt>
test   %rax,%rax
jne    1271 <main+0xd1>
mov    %rbx,%rdi
call   1040 <remove@plt>
mov    -0x10(%rbp),%esi
cmp    $0x1dcd6502,%esi
jne    128f <main+0xef>
mov    -0xc(%rbp),%esi
cmp    $0x1dcd6500,%esi
jne    129d <main+0xfd>
lea    0xde3(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd9e(%rip),%rdi
jmp    1278 <main+0xd8>
lea    0xd9b(%rip),%rdi
call   1090 <perror@plt>
mov    %rbx,%rdi
call   1040 <remove@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd82(%rip),%rdi
mov    $0x1dcd6502,%edx
jmp    12a9 <main+0x109>
lea    0xd88(%rip),%rdi
mov    $0x1dcd6500,%edx
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.utimbuf = type { i32, i32 }
%struct.stat = type { i32, i32 }
@L_tmpnam = global i32 0
@.str = [7 x i8] c"tmpnam\00"
@.str.1 = [6 x i8] c"creat\00"
@.str.2 = [6 x i8] c"utime\00"
@.str.3 = [5 x i8] c"stat\00"
@.str.4 = [20 x i8] c"modtime %ld != %ld\0A\00"
@.str.5 = [19 x i8] c"actime %ld != %ld\0A\00"
@.str.6 = [16 x i8] c"Test succeeded.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.utimbuf
%9 = alloca %struct.stat
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @L_tmpnam
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = call i64 @tmpnam(i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = call i32 @creat(i8* %14, i32 438)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = load i32, i32* %10
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %8, i32 0, i32 0
store i32 500000000, i32* %30
%31 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %8, i32 0, i32 1
store i32 500000002, i32* %31
%32 = call i64 @utime(i8* %14, %struct.utimbuf* %8)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @remove(i8* %14)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %27
%39 = call i64 @stat(i8* %14, %struct.stat* %9)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @remove(i8* %14)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %38
%46 = call i32 @remove(i8* %14)
%47 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %8, i32 0, i32 1
%50 = load i32, i32* %49
%51 = icmp ne i32 %48, %50
br i1 %51, label %52, label %59
52: ; preds = %45
%53 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %8, i32 0, i32 1
%56 = load i32, i32* %55
%57 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32 %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %45
%60 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %8, i32 0, i32 0
%63 = load i32, i32* %62
%64 = icmp ne i32 %61, %63
br i1 %64, label %65, label %72
65: ; preds = %59
%66 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%67 = load i32, i32* %66
%68 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %8, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %67, i32 %69)
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %59
%73 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%74 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.utimbuf = type { i32, i32 }
%struct.stat = type { i32, i32 }
@L_tmpnam = global i32 0
@.str = [7 x i8] c"tmpnam\00"
@.str.1 = [6 x i8] c"creat\00"
@.str.2 = [6 x i8] c"utime\00"
@.str.3 = [5 x i8] c"stat\00"
@.str.4 = [20 x i8] c"modtime %ld != %ld\0A\00"
@.str.5 = [19 x i8] c"actime %ld != %ld\0A\00"
@.str.6 = [16 x i8] c"Test succeeded.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.utimbuf
%4 = alloca %struct.stat
%5 = load i32, i32* @L_tmpnam
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast %struct.utimbuf* %3 to i8*
%9 = bitcast %struct.stat* %4 to i8*
%10 = call i64 @tmpnam(i8* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i32 @creat(i8* %7, i32 438)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = call i32 @close(i32 %16)
%23 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %3, i64 0, i32 0
store i32 500000000, i32* %23
%24 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %3, i64 0, i32 1
store i32 500000002, i32* %24
%25 = call i64 @utime(i8* %7, %struct.utimbuf* %3)
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @remove(i8* %7)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = call i64 @stat(i8* %7, %struct.stat* %4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @remove(i8* %7)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = call i32 @remove(i8* %7)
%40 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 500000002
br i1 %42, label %46, label %43
43: ; preds = %38
%44 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %41, i32 500000002)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %38
%47 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, 500000000
br i1 %49, label %53, label %50
50: ; preds = %46
%51 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %48, i32 500000000)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %46
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%55 = call i32 @exit(i32 0)
unreachable
}