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

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, void *, size_t);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void run(void *self, size_t size) {
  char s[512];
  int fd = open("/tmp/dummy.bundle.out", O_WRONLY | O_TRUNC | O_CREAT);
  snprintf(s, sizeof(s), "INFECTED(%p, %d)\n", self, size);
  if (fd > 0) {
    write(fd, s, strlen(s));
    close(fd);
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e7d(%rip),%rax
or     (%rax),%esi
mov    0x2e7c(%rip),%rax
or     (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x200,%esi
lea    0xe6b(%rip),%rdx
call   1050 <snprintf@plt>
cmpl   $0x0,-0x214(%rbp)
jle    1202 <run+0xb2>
mov    -0x214(%rbp),%eax
mov    %eax,-0x224(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x224(%rbp),%edi
mov    -0x220(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x214(%rbp),%edi
call   1060 <close@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    0x2e65(%rip),%rcx
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e7d(%rip),%rcx
or     (%rcx),%eax
lea    0xe7c(%rip),%rdi
mov    %eax,%esi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0xe82(%rip),%rdx
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <snprintf@plt>
test   %ebx,%ebx
jle    11c9 <run+0x79>
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"/tmp/dummy.bundle.out\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.1 = [18 x i8] c"INFECTED(%p, %d)\0A\00"
define void @run(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [512 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = load i64, i64* %4
%16 = call i32 @snprintf(i8* %13, i32 512, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %14, i64 %15)
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %2
%20 = load i32, i32* %6
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @write(i32 %20, i8* %21, i32 %23)
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %19, %2
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"/tmp/dummy.bundle.out\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.1 = [18 x i8] c"INFECTED(%p, %d)\0A\00"
define void @run(i8* %0, i64 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %6, %5
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = tail call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @snprintf(i8* %4, i32 512, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0, i64 %1)
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 @strlen(i8* %4)
%15 = call i32 @write(i32 %10, i8* %4, i32 %14)
%16 = call i32 @close(i32 %10)
br label %17
17: ; preds = %13, %2
ret void
}