#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__ strcmp(char *, char *);
int strings_equal(char *a, char *b) {
  int both_null = a == NULL ? (b == NULL ? 1 : 0) : 0;
  if (both_null)
    return 1;
  if (a == NULL)
    return 0;
  if (b == NULL)
    return 0;
  return strcmp(a, b) == 0;
}


x86 assembly (clang, -O0):
<strings_equal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1145 <strings_equal+0x35>
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x20(%rbp)
jmp    114f <strings_equal+0x3f>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    114f <strings_equal+0x3f>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     116b <strings_equal+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    11b5 <strings_equal+0xa5>
cmpq   $0x0,-0x10(%rbp)
jne    1182 <strings_equal+0x72>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <strings_equal+0xa5>
cmpq   $0x0,-0x18(%rbp)
jne    1199 <strings_equal+0x89>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <strings_equal+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strings_equal>:
mov    %rdi,%rax
or     %rsi,%rax
sete   %al
test   %rdi,%rdi
je     1133 <strings_equal+0x23>
test   %rsi,%rsi
je     1133 <strings_equal+0x23>
push   %rax
call   1030 <strcmp@plt>
test   %rax,%rax
sete   %al
add    $0x8,%rsp
movzbl %al,%eax
ret

LLVM IR (-O0):
define i32 @strings_equal(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
%12 = zext i1 %11 to i64
%13 = select i1 %11, i32 1, i32 0
br label %15
14: ; preds = %2
br label %15
15: ; preds = %14, %9
%16 = phi i32 [ %13, %9 ], [ 0, %14 ]
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 1, i32* %3
br label %34
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 0, i32* %3
br label %34
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 0, i32* %3
br label %34
28: ; preds = %24
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = call i64 @strcmp(i8* %29, i8* %30)
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i32
store i32 %33, i32* %3
br label %34
34: ; preds = %28, %27, %23, %19
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @strings_equal(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = and i1 %3, %4
%6 = or i1 %3, %4
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i64 @strcmp(i8* %0, i8* %1)
%9 = icmp eq i64 %8, 0
br label %10
10: ; preds = %2, %7
%11 = phi i1 [ %9, %7 ], [ %5, %2 ]
%12 = zext i1 %11 to i32
ret i32 %12
}