#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_RDWR;
char *calloc(int, int);
scalar_t__ count_processes();
int /*<<< orphan*/ free(char *);
int list_processes(char *, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int fd2 = open("/sdcard/t.txt", O_RDWR | O_CREAT);
  printf("test, world! I am an Android app. %d\n", fd2);
  int i = (int)count_processes();
  char *buffer = calloc((i * 43 + 1), 1);
  int retval = 0;
  if ((retval = list_processes(buffer, (i * 43 + 1))) > 0) {
    printf("%s\n", buffer);
    printf("Return value=%d\n", retval);
  }
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    0x2e79(%rip),%rax
or     (%rax),%esi
lea    0xe78(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <count_processes@plt>
mov    %eax,-0xc(%rbp)
imul   $0x2b,-0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
imul   $0x2b,-0xc(%rbp),%esi
add    $0x1,%esi
call   1080 <list_processes@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1206 <main+0xa6>
mov    -0x18(%rbp),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e66(%rip),%rax
mov    0x2e77(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe74(%rip),%rdi
call   1080 <open@plt>
lea    0xe76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <count_processes@plt>
imul   $0x2b,%eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1090 <list_processes@plt>
test   %eax,%eax
jle    11e5 <main+0x75>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe58(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/sdcard/t.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [38 x i8] c"test, world! I am an Android app. %d\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [17 x i8] c"Return value=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i64 (...) @count_processes()
%13 = trunc i64 %12 to i32
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = mul nsw i32 %14, 43
%16 = add nsw i32 %15, 1
%17 = call i8* @calloc(i32 %16, i32 1)
store i8* %17, i8** %4
store i32 0, i32* %5
%18 = load i8*, i8** %4
%19 = load i32, i32* %3
%20 = mul nsw i32 %19, 43
%21 = add nsw i32 %20, 1
%22 = call i32 @list_processes(i8* %18, i32 %21)
store i32 %22, i32* %5
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %0
%25 = load i8*, i8** %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %24, %0
%30 = load i8*, i8** %4
%31 = call i32 @free(i8* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/sdcard/t.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [38 x i8] c"test, world! I am an Android app. %d\0A\00"
@.str.3 = [17 x i8] c"Return value=%d\0A\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i64 (...) @count_processes()
%7 = trunc i64 %6 to i32
%8 = mul nsw i32 %7, 43
%9 = add nsw i32 %8, 1
%10 = tail call i8* @calloc(i32 %9, i32 1)
%11 = tail call i32 @list_processes(i8* %10, i32 %9)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) %10)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %11)
br label %16
16: ; preds = %13, %0
%17 = tail call i32 @free(i8* %10)
ret i32 0
}