#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 */
scalar_t__ cg_read(char const *, char const *, char *, size_t);
char *malloc(size_t);
int strcmp(char const *, char *);
int strlen(char const *);
int cg_read_strcmp(const char *cgroup, const char *control,
                   const char *expected) {
  size_t size = strlen(expected) + 1;
  char *buf;
  buf = malloc(size);
  if (!buf)
    return -1;
  if (cg_read(cgroup, control, buf, size))
    return -1;
  return strcmp(expected, buf);
}


x86 assembly (clang, -O0):
<cg_read_strcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    118a <cg_read_strcmp+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <cg_read_strcmp+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <cg_read@plt>
cmp    $0x0,%rax
je     11b5 <cg_read_strcmp+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <cg_read_strcmp+0x85>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_read_strcmp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rbx
mov    %rbx,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     1186 <cg_read_strcmp+0x46>
mov    %rax,%r13
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1030 <cg_read@plt>
test   %rax,%rax
je     1195 <cg_read_strcmp+0x55>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %r12,%rdi
mov    %r13,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <strcmp@plt>

LLVM IR (-O0):
define i32 @cg_read_strcmp(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
store i64 %13, i64* %8
%14 = load i64, i64* %8
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %9
%16 = load i8*, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %3
store i32 -1, i32* %4
br label %31
19: ; preds = %3
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = load i8*, i8** %9
%23 = load i64, i64* %8
%24 = call i64 @cg_read(i8* %20, i8* %21, i8* %22, i64 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 -1, i32* %4
br label %31
27: ; preds = %19
%28 = load i8*, i8** %7
%29 = load i8*, i8** %9
%30 = call i32 @strcmp(i8* %28, i8* %29)
store i32 %30, i32* %4
br label %31
31: ; preds = %27, %26, %18
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @cg_read_strcmp(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = add nsw i32 %4, 1
%6 = sext i32 %5 to i64
%7 = tail call i8* @malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = tail call i64 @cg_read(i8* %0, i8* %1, i8* %7, i64 %6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %2, i8* %7)
br label %14
14: ; preds = %9, %3, %12
%15 = phi i32 [ %13, %12 ], [ -1, %3 ], [ -1, %9 ]
ret i32 %15
}