#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)
    size = 32;
  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    117c <cg_read_strcmp+0x2c>
movq   $0x20,-0x28(%rbp)
jmp    118e <cg_read_strcmp+0x3e>
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    11b2 <cg_read_strcmp+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <cg_read_strcmp+0xb5>
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     11e6 <cg_read_strcmp+0x96>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <cg_read_strcmp+0xb5>
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    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
test   %rdx,%rdx
je     1179 <cg_read_strcmp+0x29>
mov    %r15,%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r13
jmp    117f <cg_read_strcmp+0x2f>
mov    $0x20,%r13d
mov    %r13,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11c1 <cg_read_strcmp+0x71>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %r13,%rcx
call   1040 <cg_read@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    11b7 <cg_read_strcmp+0x67>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11c6 <cg_read_strcmp+0x76>
mov    $0xffffffff,%ebp
mov    %ebp,%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 i64 32, i64* %8
br label %19
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, %13
%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
%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 %9, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %2)
%7 = add nsw i32 %6, 1
%8 = sext i32 %7 to i64
br label %9
9: ; preds = %3, %5
%10 = phi i64 [ %8, %5 ], [ 32, %3 ]
%11 = tail call i8* @malloc(i64 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = tail call i64 @cg_read(i8* %0, i8* %1, i8* %11, i64 %10)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %2, i8* %11)
br label %18
18: ; preds = %13, %16
%19 = phi i32 [ %17, %16 ], [ -1, %13 ]
%20 = tail call i32 @free(i8* %11)
br label %21
21: ; preds = %18, %9
%22 = phi i32 [ -1, %9 ], [ %19, %18 ]
ret i32 %22
}