#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 O_CREAT;
int O_SYNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ do_write(int, char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ usleep(int);
void logger() {
  int fd;
  char *buf;
  buf = malloc(1024);
  strcpy(buf, "[*] INFO Writing a log message.\n");
  fd = open("log.data", O_CREAT | O_WRONLY | O_SYNC, 0644);
  while (1) {
    usleep(20000);
    do_write(fd, buf, 1024);
  }
  close(fd);
  free(buf);
}


x86 assembly (clang, -O0):
<logger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    0x2e42(%rip),%rax
or     (%rax),%esi
mov    0x2e51(%rip),%rax
or     (%rax),%esi
lea    0xe89(%rip),%rdi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
mov    $0x4e20,%edi
call   1070 <usleep@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1040 <do_write@plt>
jmp    11a5 <logger+0x55>

x86 assembly (clang, -O2):
<logger>:
push   %rbp
push   %rbx
push   %rax
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe99(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    0x2e82(%rip),%rax
mov    0x2e4b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e58(%rip),%rax
or     (%rax),%esi
lea    0xe90(%rip),%rdi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,%ebp
nopl   (%rax)
mov    $0x4e20,%edi
call   1070 <usleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <do_write@plt>
jmp    11a0 <logger+0x50>

LLVM IR (-O0):
@.str = [33 x i8] c"[*] INFO Writing a log message.\0A\00"
@.str.1 = [9 x i8] c"log.data\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_SYNC = global i32 0
define void @logger() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i8* @malloc(i32 1024)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_WRONLY
%8 = or i32 %6, %7
%9 = load i32, i32* @O_SYNC
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 420)
store i32 %11, i32* %1
br label %12
12: ; preds = %0, %12
%13 = call i32 @usleep(i32 20000)
%14 = load i32, i32* %1
%15 = load i8*, i8** %2
%16 = call i32 @do_write(i32 %14, i8* %15, i32 1024)
br label %12
}

LLVM IR (-O2):
@.str = [33 x i8] c"[*] INFO Writing a log message.\0A\00"
@.str.1 = [9 x i8] c"log.data\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_SYNC = global i32 0
define void @logger() {
%1 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%2 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_WRONLY
%5 = or i32 %4, %3
%6 = load i32, i32* @O_SYNC
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 420)
br label %9
9: ; preds = %9, %0
%10 = tail call i32 @usleep(i32 20000)
%11 = tail call i32 @do_write(i32 %8, i8* %1, i32 1024)
br label %9
}