#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ P_tmpdir;
int /*<<< orphan*/ W_OK;
scalar_t__ access(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ *tmpfile();
int main(int argc, char *argv[]) {
  FILE *tmp;
  int i;
  int status = 0;
  if (argc != 2) {
    fprintf(stderr, "need exactly one argument\n");
    return 1;
  }
  if (access(P_tmpdir, W_OK) != 0) {
    fprintf(stderr, "Cannot do test due to missing write access to `%s': %s\n",
            strerror(errno));
    return 1;
  }
  for (i = 0; i < 100; i++) {
    tmp = tmpfile();
    if (tmp == NULL) {
      perror("tmpfile");
      status = 1;
      continue;
    }
    if (fprintf(tmp, "%s", argv[1]) <= 0) {
      perror("fwrite");
      status = 1;
    }
    if (fclose(tmp) != 0) {
      perror("fclose");
      status = 1;
    }
  }
  return status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ab <main+0x4b>
mov    0x2e42(%rip),%rax
mov    (%rax),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12be <main+0x15e>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     1209 <main+0xa9>
mov    0x2dfd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rdx
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12be <main+0x15e>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    12b8 <main+0x158>
mov    $0x0,%al
call   1040 <tmpfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1248 <main+0xe8>
lea    0xe1c(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x20(%rbp)
jmp    12aa <main+0x14a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jg     127f <main+0x11f>
lea    0xdeb(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     12a5 <main+0x145>
lea    0xdcc(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x20(%rbp)
jmp    12aa <main+0x14a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1210 <main+0xb0>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11cd <main+0x5d>
mov    %rsi,%r13
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
je     1205 <main+0x95>
mov    0x2e2a(%rip),%rax
mov    (%rax),%rbx
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11ed <main+0x7d>
mov    0x2dfc(%rip),%rax
mov    (%rax),%rcx
lea    0xe22(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x64,%ebx
lea    0xe42(%rip),%r15
lea    0xe4d(%rip),%r14
xor    %r12d,%r12d
jmp    1235 <main+0xc5>
call   1070 <perror@plt>
mov    $0x1,%r12d
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
je     11f3 <main+0x83>
xor    %eax,%eax
call   1040 <tmpfile@plt>
mov    %r15,%rdi
test   %rax,%rax
je     121d <main+0xad>
mov    %rax,%rbp
mov    0x8(%r13),%rdx
mov    %rax,%rdi
lea    0xe06(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %rax,%rax
jle    1273 <main+0x103>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
test   %rax,%rax
je     1230 <main+0xc0>
jmp    121d <main+0xad>
lea    0xde4(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%r12d
jmp    1261 <main+0xf1>

LLVM IR (-O0):
@stderr = global i32* null
@.str = [27 x i8] c"need exactly one argument\0A\00"
@P_tmpdir = global i32 0
@W_OK = global i32 0
@.str.1 = [56 x i8] c"Cannot do test due to missing write access to `%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [8 x i8] c"tmpfile\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [7 x i8] c"fwrite\00"
@.str.5 = [7 x i8] c"fclose\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32*, i32** @stderr
%13 = call i64 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %55
14: ; preds = %2
%15 = load i32, i32* @P_tmpdir
%16 = load i32, i32* @W_OK
%17 = call i64 @access(i32 %15, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32*, i32** @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i64 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %55
24: ; preds = %14
store i32 0, i32* %7
br label %25
25: ; preds = %50, %24
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 100
br i1 %27, label %28, label %53
28: ; preds = %25
%29 = call i32* (...) @tmpfile()
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %8
br label %50
34: ; preds = %28
%35 = load i32*, i32** %6
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i64 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = icmp sle i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %8
br label %43
43: ; preds = %41, %34
%44 = load i32*, i32** %6
%45 = call i64 @fclose(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %8
br label %49
49: ; preds = %47, %43
br label %50
50: ; preds = %49, %32
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %25
53: ; preds = %25
%54 = load i32, i32* %8
store i32 %54, i32* %3
br label %55
55: ; preds = %53, %19, %11
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [27 x i8] c"need exactly one argument\0A\00"
@P_tmpdir = global i32 0
@W_OK = global i32 0
@.str.1 = [56 x i8] c"Cannot do test due to missing write access to `%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [8 x i8] c"tmpfile\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [7 x i8] c"fwrite\00"
@.str.5 = [7 x i8] c"fclose\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32*, i32** @stderr
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 26, i64 1, i32* %5)
br label %41
7: ; preds = %2
%8 = load i32, i32* @P_tmpdir
%9 = load i32, i32* @W_OK
%10 = tail call i64 @access(i32 %8, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 1
br label %19
14: ; preds = %7
%15 = load i32*, i32** @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %41
19: ; preds = %12, %37
%20 = phi i32 [ 0, %12 ], [ %38, %37 ]
%21 = phi i32 [ 0, %12 ], [ %39, %37 ]
%22 = tail call i32* (...) @tmpfile()
%23 = icmp eq i32* %22, null
br i1 %23, label %34, label %24
24: ; preds = %19
%25 = load i8*, i8** %13
%26 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = icmp slt i64 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = phi i32 [ 1, %28 ], [ %20, %24 ]
%32 = tail call i64 @fclose(i32* %22)
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %30, %19
%35 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %19 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %30 ]
%36 = tail call i32 @perror(i8* %35)
br label %37
37: ; preds = %34, %30
%38 = phi i32 [ %31, %30 ], [ 1, %34 ]
%39 = add nuw nsw i32 %21, 1
%40 = icmp eq i32 %39, 100
br i1 %40, label %41, label %19
41: ; preds = %37, %14, %4
%42 = phi i32 [ 1, %4 ], [ 1, %14 ], [ %38, %37 ]
ret i32 %42
}