#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 */
size_t strnlen(char *, size_t);
const char *find_snap_name(char *buf, size_t num_read) {
  size_t argv0_len = strnlen(buf, num_read);
  if (argv0_len + 1 >= num_read) {
    return NULL;
  }
  char *snap_name = &buf[argv0_len + 1];
  if (*snap_name == '\0') {
    return NULL;
  }
  return snap_name;
}


x86 assembly (clang, -O0):
<find_snap_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strnlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
cmp    -0x18(%rbp),%rax
jb     1150 <find_snap_name+0x40>
movq   $0x0,-0x8(%rbp)
jmp    1188 <find_snap_name+0x78>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1180 <find_snap_name+0x70>
movq   $0x0,-0x8(%rbp)
jmp    1188 <find_snap_name+0x78>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_snap_name>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <strnlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
cmp    %rbx,%rcx
jae    113c <find_snap_name+0x2c>
lea    (%r14,%rcx,1),%rdx
xor    %eax,%eax
cmpb   $0x0,(%r14,%rcx,1)
cmovne %rdx,%rax
jmp    113e <find_snap_name+0x2e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @find_snap_name(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i8*, i8** %4
%9 = load i64, i64* %5
%10 = call i64 @strnlen(i8* %8, i64 %9)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = add i64 %11, 1
%13 = load i64, i64* %5
%14 = icmp uge i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %2
store i8* null, i8** %3
br label %28
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load i64, i64* %6
%19 = add i64 %18, 1
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %16
store i8* null, i8** %3
br label %28
26: ; preds = %16
%27 = load i8*, i8** %7
store i8* %27, i8** %3
br label %28
28: ; preds = %26, %25, %15
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define i8* @find_snap_name(i8* %0, i64 %1) {
%3 = tail call i64 @strnlen(i8* %0, i64 %1)
%4 = add i64 %3, 1
%5 = icmp ult i64 %4, %1
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %0, i64 %4
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = select i1 %9, i8* null, i8* %7
br label %11
11: ; preds = %2, %6
%12 = phi i8* [ %10, %6 ], [ null, %2 ]
ret i8* %12
}