#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*/ exit(int);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sbrk(int /*<<< orphan*/);
int func(int arg) {
  int j;
  for (j = 0; j < 0x100; j++)
    if (malloc(0x8000) == NULL) {
      perror("malloc");
      exit(1);
    }
  printf("CHILD: Program break in child:  %10p\n", sbrk(0));
  return arg;
}


x86 assembly (clang, -O0):
<func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x100,-0x8(%rbp)
jge    11ac <func+0x5c>
mov    $0x8000,%edi
call   1050 <malloc@plt>
cmp    $0x0,%rax
jne    1199 <func+0x49>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    119e <func+0x4e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1162 <func+0x12>
xor    %edi,%edi
call   1040 <sbrk@plt>
mov    %eax,%esi
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x100,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x8000,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1192 <func+0x42>
add    $0xffffffff,%ebp
jne    1160 <func+0x10>
xor    %edi,%edi
call   1040 <sbrk@plt>
lea    0xe85(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [38 x i8] c"CHILD: Program break in child: %10p\0A\00"
define i32 @func(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %14, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 256
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = call i32* @malloc(i32 32768)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %7
br label %14
14: ; preds = %13
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %4
17: ; preds = %4
%18 = call i32 @sbrk(i32 0)
%19 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [38 x i8] c"CHILD: Program break in child: %10p\0A\00"
define i32 @func(i32 returned %0) {
br label %5
2: ; preds = %5
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 256
br i1 %4, label %12, label %5
5: ; preds = %1, %2
%6 = phi i32 [ 0, %1 ], [ %3, %2 ]
%7 = tail call i32* @malloc(i32 32768)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %2
9: ; preds = %5
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = tail call i32 @sbrk(i32 0)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %13)
ret i32 %0
}