#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 atoi(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ setpgid(int /*<<< orphan*/, int);
void test_oom_infinite(char *pgids) {
  if (pgids != NULL) {
    int pgid = atoi(pgids);
    setpgid(0, pgid);
  }
  while (1) {
    char *p = (char *)malloc(4096);
    if (p != NULL) {
      p[0] = 0xFF;
    } else {
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<test_oom_infinite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     116d <test_oom_infinite+0x2d>
mov    -0x8(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
xor    %edi,%edi
call   1050 <setpgid@plt>
jmp    1172 <test_oom_infinite+0x32>
mov    $0x1000,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1197 <test_oom_infinite+0x57>
mov    -0x18(%rbp),%rax
movb   $0xff,(%rax)
jmp    11a1 <test_oom_infinite+0x61>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1172 <test_oom_infinite+0x32>

x86 assembly (clang, -O2):
<test_oom_infinite>:
push   %rax
test   %rdi,%rdi
je     1163 <test_oom_infinite+0x23>
call   1040 <atoi@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1050 <setpgid@plt>
jmp    1163 <test_oom_infinite+0x23>
cs nopw 0x0(%rax,%rax,1)
movb   $0xff,(%rax)
mov    $0x1000,%edi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1160 <test_oom_infinite+0x20>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
define void @test_oom_infinite(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 @atoi(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i32 @setpgid(i32 0, i32 %10)
br label %12
12: ; preds = %7, %1
br label %13
13: ; preds = %12, %23
%14 = call i64 @malloc(i32 4096)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 0
store i8 -1, i8* %20
br label %23
21: ; preds = %13
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %18
br label %13
}

LLVM IR (-O2):
define void @test_oom_infinite(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = tail call i32 @atoi(i8* %0)
%5 = tail call i32 @setpgid(i32 0, i32 %4)
br label %6
6: ; preds = %3, %1
%7 = tail call i64 @malloc(i32 4096)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6, %9
%10 = phi i64 [ %12, %9 ], [ %7, %6 ]
%11 = inttoptr i64 %10 to i8*
store i8 -1, i8* %11
%12 = tail call i64 @malloc(i32 4096)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %9
14: ; preds = %9, %6
%15 = tail call i32 @exit(i32 1)
unreachable
}