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


x86 assembly (clang, -O0):
<cg_read_strcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117b <cg_read_strcmp+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <cg_read_strcmp+0xb4>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b1 <cg_read_strcmp+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <cg_read_strcmp+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <cg_read@plt>
cmp    $0x0,%rax
je     11e5 <cg_read_strcmp+0x95>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <cg_read_strcmp+0xb4>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_read_strcmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r13d
test   %rdx,%rdx
je     11bf <cg_read_strcmp+0x6f>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rdx,%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rbp
mov    %rbp,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11bf <cg_read_strcmp+0x6f>
mov    %rax,%r14
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    %rbp,%rcx
call   1040 <cg_read@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
jne    11b7 <cg_read_strcmp+0x67>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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*
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %3
store i32 -1, i32* %4
br label %42
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
store i64 %18, i64* %8
br label %19
19: ; preds = %14
%20 = load i64, i64* %8
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 -1, i32* %4
br label %42
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = load i8*, i8** %9
%29 = load i64, i64* %8
%30 = call i64 @cg_read(i8* %26, i8* %27, i8* %28, i64 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i8*, i8** %9
%34 = call i32 @free(i8* %33)
store i32 -1, i32* %4
br label %42
35: ; preds = %25
%36 = load i8*, i8** %7
%37 = load i8*, i8** %9
%38 = call i32 @strcmp(i8* %36, i8* %37)
store i32 %38, i32* %10
%39 = load i8*, i8** %9
%40 = call i32 @free(i8* %39)
%41 = load i32, i32* %10
store i32 %41, i32* %4
br label %42
42: ; preds = %35, %32, %24, %13
%43 = load i32, i32* %4
ret i32 %43
}

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