#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*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
double log(double);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *tmpfile();
void work() {
  FILE *f;
  int i;
  double x = 4.5;
  f = tmpfile();
  for (i = 0; i < 10000; i++) {
    fprintf(f, "Do some output\n");
    if (ferror(f)) {
      fprintf(stderr, "Error writing to temporary file\n");
      exit(1);
    }
  }
  for (i = 0; i < 1000000; i++)
    x = log(x * x + 3.21);
}


x86 assembly (clang, -O0):
<work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  0xea0(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <tmpfile@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jge    11da <work+0x8a>
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11c7 <work+0x77>
mov    0x2e32(%rip),%rax
mov    (%rax),%rdi
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11cc <work+0x7c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1177 <work+0x27>
movl   $0x0,-0xc(%rbp)
cmpl   $0xf4240,-0xc(%rbp)
jge    1220 <work+0xd0>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe04(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e1 <work+0x91>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <tmpfile@plt>
mov    %rax,%rbx
mov    $0x2710,%ebp
lea    0xea6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11cb <work+0x7b>
add    $0xffffffff,%ebp
jne    1170 <work+0x20>
movsd  0xe61(%rip),%xmm0
mov    $0xf4240,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mulsd  %xmm0,%xmm0
addsd  0xe4c(%rip),%xmm0
call   1050 <log@plt>
add    $0xffffffff,%ebx
jne    11b0 <work+0x60>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e0e(%rip),%rax
mov    (%rax),%rcx
lea    0xe44(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"Do some output\0A\00"
@stderr = global i32* null
@.str.1 = [33 x i8] c"Error writing to temporary file\0A\00"
define void @work() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca double
store double 4.500000e+00, double* %3
%4 = call i32* (...) @tmpfile()
store i32* %4, i32** %1
store i32 0, i32* %2
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 10000
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = load i32*, i32** %1
%10 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = load i32*, i32** %1
%12 = call i64 @ferror(i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = load i32*, i32** @stderr
%16 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %8
br label %19
19: ; preds = %18
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %5
22: ; preds = %5
store i32 0, i32* %2
br label %23
23: ; preds = %31, %22
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, 1000000
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load double, double* %3
%28 = load double, double* %3
%29 = call double @llvm.fmuladd.f64(double %27, double %28, double 3.210000e+00)
%30 = call double @log(double %29)
store double %30, double* %3
br label %31
31: ; preds = %26
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %23
34: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Do some output\0A\00"
@stderr = global i32* null
@.str.1 = [33 x i8] c"Error writing to temporary file\0A\00"
define void @work() {
%1 = tail call i32* (...) @tmpfile()
br label %5
2: ; preds = %5
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 10000
br i1 %4, label %14, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 15, i64 1, i32* %1)
%8 = tail call i64 @ferror(i32* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %2, label %10
10: ; preds = %5
%11 = load i32*, i32** @stderr
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 32, i64 1, i32* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2, %14
%15 = phi double [ %18, %14 ], [ 4.500000e+00, %2 ]
%16 = phi i32 [ %19, %14 ], [ 0, %2 ]
%17 = tail call double @llvm.fmuladd.f64(double %15, double %15, double 3.210000e+00)
%18 = tail call double @log(double %17)
%19 = add nuw nsw i32 %16, 1
%20 = icmp eq i32 %19, 1000000
br i1 %20, label %21, label %14
21: ; preds = %14
ret void
}