#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 scalar_t__ off_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int ftruncate(int, int);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int);
int read(int, char *, int);
char *tmpnam(int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
main() {
  char *path = tmpnam(NULL);
  int exitStatus = 1;
  if (path != NULL) {
    int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
    if (fd != -1) {
      if (write(fd, "0", 1) == 1) {
        off_t pos = lseek(fd, 0, SEEK_CUR);
        if (pos != (off_t)-1) {
          if (ftruncate(fd, 512) != -1) {
            if (pos == lseek(fd, 0, SEEK_CUR)) {
              if (lseek(fd, 0, SEEK_SET) == 0) {
                char buf[512];
                if (read(fd, buf, 512) == 512)
                  exitStatus = 0;
              }
            }
          }
        }
      }
      close(fd);
      unlink(path);
    }
  }
  return exitStatus;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <tmpnam@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12df <main+0x15f>
mov    -0x10(%rbp),%rdi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
mov    0x2e33(%rip),%rax
or     (%rax),%esi
mov    0x2e22(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     12da <main+0x15a>
mov    -0x18(%rbp),%edi
lea    0xe0f(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
jne    12c9 <main+0x149>
mov    -0x18(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
je     12c4 <main+0x144>
mov    -0x18(%rbp),%edi
mov    $0x200,%esi
call   1050 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     12bf <main+0x13f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %rax,%rcx
mov    -0x228(%rbp),%rax
cmp    %rcx,%rax
jne    12ba <main+0x13a>
mov    -0x18(%rbp),%edi
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0x0,%rax
jne    12b5 <main+0x135>
mov    -0x18(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
cmp    $0x200,%eax
jne    12b0 <main+0x130>
movl   $0x0,-0x14(%rbp)
jmp    12b5 <main+0x135>
jmp    12ba <main+0x13a>
jmp    12bf <main+0x13f>
jmp    12c4 <main+0x144>
jmp    12c9 <main+0x149>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
jmp    12df <main+0x15f>
mov    -0x14(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
xor    %edi,%edi
call   10a0 <tmpnam@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     127a <main+0xfa>
mov    %rax,%rbx
mov    0x2e29(%rip),%rax
mov    0x2e42(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e2f(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     127a <main+0xfa>
mov    %eax,%ebp
lea    0xe1e(%rip),%rsi
mov    $0x1,%r14d
mov    %eax,%edi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
jne    126b <main+0xeb>
mov    0x2dd0(%rip),%r12
mov    (%r12),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     126b <main+0xeb>
mov    %rax,%r15
mov    %ebp,%edi
mov    $0x200,%esi
call   1050 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     126b <main+0xeb>
mov    (%r12),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    %rax,%r15
jne    126b <main+0xeb>
mov    0x2d80(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
test   %rax,%rax
jne    126b <main+0xeb>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x200,%edx
call   1080 <read@plt>
xor    %r14d,%r14d
cmp    $0x200,%eax
setne  %r14b
mov    %ebp,%edi
call   1070 <close@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %r14d,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [2 x i8] c"0\00"
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca [512 x i8]
store i32 0, i32* %1
%7 = call i8* @tmpnam(i32* null)
store i8* %7, i8** %2
store i32 1, i32* %3
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %62
10: ; preds = %0
%11 = load i8*, i8** %2
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_CREAT
%14 = or i32 %12, %13
%15 = load i32, i32* @O_TRUNC
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %11, i32 %16, i32 438)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %61
20: ; preds = %10
%21 = load i32, i32* %4
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %56
24: ; preds = %20
%25 = load i32, i32* %4
%26 = load i32, i32* @SEEK_CUR
%27 = call i64 @lseek(i32 %25, i32 0, i32 %26)
store i64 %27, i64* %5
%28 = load i64, i64* %5
%29 = icmp ne i64 %28, -1
br i1 %29, label %30, label %55
30: ; preds = %24
%31 = load i32, i32* %4
%32 = call i32 @ftruncate(i32 %31, i32 512)
%33 = icmp ne i32 %32, -1
br i1 %33, label %34, label %54
34: ; preds = %30
%35 = load i64, i64* %5
%36 = load i32, i32* %4
%37 = load i32, i32* @SEEK_CUR
%38 = call i64 @lseek(i32 %36, i32 0, i32 %37)
%39 = icmp eq i64 %35, %38
br i1 %39, label %40, label %53
40: ; preds = %34
%41 = load i32, i32* %4
%42 = load i32, i32* @SEEK_SET
%43 = call i64 @lseek(i32 %41, i32 0, i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %52
45: ; preds = %40
%46 = load i32, i32* %4
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%48 = call i32 @read(i32 %46, i8* %47, i32 512)
%49 = icmp eq i32 %48, 512
br i1 %49, label %50, label %51
50: ; preds = %45
store i32 0, i32* %3
br label %51
51: ; preds = %50, %45
br label %52
52: ; preds = %51, %40
br label %53
53: ; preds = %52, %34
br label %54
54: ; preds = %53, %30
br label %55
55: ; preds = %54, %24
br label %56
56: ; preds = %55, %20
%57 = load i32, i32* %4
%58 = call i32 @close(i32 %57)
%59 = load i8*, i8** %2
%60 = call i32 @unlink(i8* %59)
br label %61
61: ; preds = %56, %10
br label %62
62: ; preds = %61, %0
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [2 x i8] c"0\00"
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca [512 x i8]
%2 = tail call i8* @tmpnam(i32* null)
%3 = icmp eq i8* %2, null
br i1 %3, label %39, label %4
4: ; preds = %0
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = tail call i32 @open(i8* %2, i32 %9, i32 438)
%11 = icmp eq i32 %10, -1
br i1 %11, label %39, label %12
12: ; preds = %4
%13 = tail call i32 @write(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %35
15: ; preds = %12
%16 = load i32, i32* @SEEK_CUR
%17 = tail call i64 @lseek(i32 %10, i32 0, i32 %16)
%18 = icmp eq i64 %17, -1
br i1 %18, label %35, label %19
19: ; preds = %15
%20 = tail call i32 @ftruncate(i32 %10, i32 512)
%21 = icmp eq i32 %20, -1
br i1 %21, label %35, label %22
22: ; preds = %19
%23 = load i32, i32* @SEEK_CUR
%24 = tail call i64 @lseek(i32 %10, i32 0, i32 %23)
%25 = icmp eq i64 %17, %24
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load i32, i32* @SEEK_SET
%28 = tail call i64 @lseek(i32 %10, i32 0, i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%32 = call i32 @read(i32 %10, i8* %31, i32 512)
%33 = icmp ne i32 %32, 512
%34 = zext i1 %33 to i32
br label %35
35: ; preds = %15, %22, %30, %26, %19, %12
%36 = phi i32 [ 1, %12 ], [ %34, %30 ], [ 1, %26 ], [ 1, %22 ], [ 1, %19 ], [ 1, %15 ]
%37 = tail call i32 @close(i32 %10)
%38 = tail call i32 @unlink(i8* %2)
br label %39
39: ; preds = %4, %35, %0
%40 = phi i32 [ 1, %0 ], [ %36, %35 ], [ 1, %4 ]
ret i32 %40
}