#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 */
typedef int /*<<< orphan*/ uint64_t;
struct sysinfo {
  int dummy;
};

/* Variables and functions */
scalar_t__ mem_alerts_init(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, int /*<<< orphan*/ *);
int sysinfo(struct sysinfo *);
int main(int argc, char *argv[]) {
  int ret;
  uint64_t total_mem;
  struct sysinfo si;
  if (argc < ((2) + 1)) {
    printf("test_mem_alerts <memcg> <limit_bytes>\n");
    return 0;
  }
  if ((ret = sysinfo(&si)) < 0) {
    printf("Error getting sysinfo\n");
    return ret;
  }
  sscanf(argv[2], "%llu", &total_mem);
  if (mem_alerts_init(argv[1], total_mem) != 0) {
    printf("failed\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1178 <main+0x38>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e9 <main+0xa9>
lea    -0x20(%rbp),%rdi
call   1050 <sysinfo@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11a4 <main+0x64>
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e9 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe8b(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%esi
call   1060 <mem_alerts_init@plt>
cmp    $0x0,%rax
je     11e2 <main+0xa2>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jg     115c <main+0x1c>
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    11ad <main+0x6d>
mov    %rsi,%r14
lea    0x10(%rsp),%rdi
call   1050 <sysinfo@plt>
test   %eax,%eax
js     119f <main+0x5f>
mov    0x10(%r14),%rdi
lea    0xe88(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1040 <sscanf@plt>
mov    0x8(%r14),%rdi
mov    0xc(%rsp),%esi
call   1060 <mem_alerts_init@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11ad <main+0x6d>
lea    0xe68(%rip),%rdi
jmp    11a8 <main+0x68>
mov    %eax,%ebx
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sysinfo = type { i32 }
@.str = [39 x i8] c"test_mem_alerts <memcg> <limit_bytes>\0A\00"
@.str.1 = [23 x i8] c"Error getting sysinfo\0A\00"
@.str.2 = [5 x i8] c"%llu\00"
@.str.3 = [8 x i8] c"failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sysinfo
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %33
13: ; preds = %2
%14 = call i32 @sysinfo(%struct.sysinfo* %8)
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %33
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* %7
%28 = call i64 @mem_alerts_init(i8* %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %19
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %19
store i32 0, i32* %3
br label %33
33: ; preds = %32, %16, %11
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
%struct.sysinfo = type { i32 }
@.str.2 = [5 x i8] c"%llu\00"
@str = [7 x i8] c"failed\00"
@str.4 = [22 x i8] c"Error getting sysinfo\00"
@str.5 = [38 x i8] c"test_mem_alerts <memcg> <limit_bytes>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sysinfo
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sysinfo* %4 to i8*
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
br label %26
10: ; preds = %2
%11 = call i32 @sysinfo(%struct.sysinfo* %4)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0))
br label %26
15: ; preds = %10
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* %3
%22 = call i64 @mem_alerts_init(i8* %20, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %15
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %15, %24, %13, %8
%27 = phi i32 [ 0, %8 ], [ %11, %13 ], [ 0, %24 ], [ 0, %15 ]
ret i32 %27
}