#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_APPEND;
int O_CREAT;
int O_WRONLY;
char *getDataLinux(char **);
char *malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ serialReceiveInit(int, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int verbose = 0;
  int settings = 1;
  serialReceiveInit(verbose, settings);
  char *mydata = malloc(sizeof(char) * 10);
  char *outdata = getDataLinux(&mydata);
  if (outdata) {
    int fd = open("foofile", O_WRONLY | O_APPEND | O_CREAT, 0666);
    write(fd, "\n", sizeof("\n"));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <serialReceiveInit@plt>
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <getDataLinux@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e1 <main+0x91>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
mov    0x2e41(%rip),%rax
or     (%rax),%esi
lea    0xe40(%rip),%rdi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    0xe31(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <serialReceiveInit@plt>
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1070 <getDataLinux@plt>
test   %rax,%rax
je     11b7 <main+0x67>
mov    0x2e51(%rip),%rax
mov    0x2e42(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e67(%rip),%rax
or     (%rax),%esi
lea    0xe66(%rip),%rdi
mov    $0x1b6,%edx
call   1060 <open@plt>
lea    0xe5d(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"foofile\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_CREAT = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1, i32* %3
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = call i32 @serialReceiveInit(i32 %7, i32 %8)
%10 = call i8* @malloc(i32 10)
store i8* %10, i8** %4
%11 = call i8* @getDataLinux(i8** %4)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %23
14: ; preds = %0
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_APPEND
%17 = or i32 %15, %16
%18 = load i32, i32* @O_CREAT
%19 = or i32 %17, %18
%20 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %19, i32 438)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %23
23: ; preds = %14, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"foofile\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_CREAT = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = tail call i32 @serialReceiveInit(i32 0, i32 1)
%3 = bitcast i8** %1 to i8*
%4 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
store i8* %4, i8** %1
%5 = call i8* @getDataLinux(i8** %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_APPEND
%10 = or i32 %9, %8
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12, i32 438)
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %15
15: ; preds = %7, %0
ret i32 0
}