#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ sname;
};
typedef TYPE_1__ X509_PURPOSE;

/* Variables and functions */
TYPE_1__ *X509_PURPOSE_get0(int);
int X509_PURPOSE_get_count();
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char const *);
int X509_PURPOSE_get_by_sname(const char *sname) {
  int i;
  X509_PURPOSE *xptmp;
  for (i = 0; i < X509_PURPOSE_get_count(); i++) {
    xptmp = X509_PURPOSE_get0(i);
    if (!strcmp(xptmp->sname, sname))
      return i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<X509_PURPOSE_get_by_sname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <X509_PURPOSE_get_count@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    119f <X509_PURPOSE_get_by_sname+0x6f>
mov    -0x14(%rbp),%edi
call   1040 <X509_PURPOSE_get0@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    118c <X509_PURPOSE_get_by_sname+0x5c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <X509_PURPOSE_get_by_sname+0x76>
jmp    1191 <X509_PURPOSE_get_by_sname+0x61>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <X509_PURPOSE_get_by_sname+0x13>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509_PURPOSE_get_by_sname>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <X509_PURPOSE_get_count@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
jle    1178 <X509_PURPOSE_get_by_sname+0x48>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1040 <X509_PURPOSE_get0@plt>
mov    (%rax),%edi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1175 <X509_PURPOSE_get_by_sname+0x45>
add    $0x1,%ebp
xor    %eax,%eax
call   1030 <X509_PURPOSE_get_count@plt>
cmp    %eax,%ebp
jl     1150 <X509_PURPOSE_get_by_sname+0x20>
jmp    1178 <X509_PURPOSE_get_by_sname+0x48>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
define i32 @X509_PURPOSE_get_by_sname(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
store i8* %0, i8** %3
store i32 0, i32* %4
br label %6
6: ; preds = %22, %1
%7 = load i32, i32* %4
%8 = call i32 (...) @X509_PURPOSE_get_count()
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %25
10: ; preds = %6
%11 = load i32, i32* %4
%12 = call %struct.TYPE_3__* @X509_PURPOSE_get0(i32 %11)
store %struct.TYPE_3__* %12, %struct.TYPE_3__** %5
%13 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i8*, i8** %3
%17 = call i32 @strcmp(i32 %15, i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %10
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %26
21: ; preds = %10
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %6
25: ; preds = %6
store i32 -1, i32* %2
br label %26
26: ; preds = %25, %19
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
define i32 @X509_PURPOSE_get_by_sname(i8* %0) {
%2 = tail call i32 (...) @X509_PURPOSE_get_count()
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %1, %11
%5 = phi i32 [ %12, %11 ], [ 0, %1 ]
%6 = tail call %struct.TYPE_3__* @X509_PURPOSE_get0(i32 %5)
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @strcmp(i32 %8, i8* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %4
%12 = add nuw nsw i32 %5, 1
%13 = tail call i32 (...) @X509_PURPOSE_get_count()
%14 = icmp slt i32 %12, %13
br i1 %14, label %4, label %15
15: ; preds = %4, %11, %1
%16 = phi i32 [ -1, %1 ], [ -1, %11 ], [ %5, %4 ]
ret i32 %16
}