#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 */
int /*<<< orphan*/ memcpy(char *, char *, int);
char *findarg(char *argbuf, char argtype) {
  char *ptr1;
  char *found = NULL;
  char type = 0;
  size_t size;
  ptr1 = argbuf;
  while (1) {
    memcpy((char *)&size, ptr1, 4);
    if (size == 0) {
      break;
    }
    if (ptr1[4] == argtype) {
      found = &ptr1[5];
      break;
    }
    ptr1 += size;
  }
  return found;
}


x86 assembly (clang, -O0):
<findarg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movq   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
cmpq   $0x0,-0x30(%rbp)
jne    1158 <findarg+0x48>
jmp    118e <findarg+0x7e>
mov    -0x18(%rbp),%rax
movsbl 0x4(%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    117d <findarg+0x6d>
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
jmp    118e <findarg+0x7e>
mov    -0x30(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1136 <findarg+0x26>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findarg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1163 <findarg+0x53>
lea    0x8(%rsp),%r14
xchg   %ax,%ax
cmp    %bpl,0x4(%rbx)
je     1167 <findarg+0x57>
add    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
jne    1140 <findarg+0x30>
xor    %ebx,%ebx
jmp    116b <findarg+0x5b>
add    $0x5,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @findarg(i8* %0, i8 signext %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i32 @memcpy(i8* %4, i8* %0, i32 4)
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %2, %16
%9 = phi i64 [ %19, %16 ], [ %6, %2 ]
%10 = phi i8* [ %17, %16 ], [ %0, %2 ]
%11 = getelementptr inbounds i8, i8* %10, i64 4
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, %1
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %10, i64 5
br label %21
16: ; preds = %8
%17 = getelementptr inbounds i8, i8* %10, i64 %9
%18 = call i32 @memcpy(i8* %4, i8* %17, i32 4)
%19 = load i64, i64* %3
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %8
21: ; preds = %16, %2, %14
%22 = phi i8* [ %15, %14 ], [ null, %2 ], [ null, %16 ]
ret i8* %22
}