#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*/ printf(char *, ...);
char *strdup(char *);
int task_find_one(char *id, char *name, int last, void *data) {
  char **ret = (char **)data;
  if (last && *ret == NULL) {
    *ret = strdup(id);
    return 0;
  }
  if (*ret == NULL)
    printf("Found more than one matching item:\n");
  *ret = strdup("TOO MANY");
  printf("%s. %s\n", id, name);
  return 0;
}


x86 assembly (clang, -O0):
<task_find_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1176 <task_find_one+0x56>
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1176 <task_find_one+0x56>
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11c5 <task_find_one+0xa5>
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1192 <task_find_one+0x72>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8b(%rip),%rdi
call   1040 <strdup@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<task_find_one>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rcx),%rax
test   %edx,%edx
je     1157 <task_find_one+0x27>
test   %rax,%rax
jne    1168 <task_find_one+0x38>
mov    %r14,%rdi
call   1050 <strdup@plt>
mov    %rax,(%rbx)
jmp    118b <task_find_one+0x5b>
test   %rax,%rax
jne    1168 <task_find_one+0x38>
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
lea    0xe91(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,(%rbx)
lea    0xe8b(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Found more than one matching item:\0A\00"
@.str.1 = [9 x i8] c"TOO MANY\00"
@.str.2 = [8 x i8] c"%s. %s\0A\00"
define i32 @task_find_one(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8**
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i8*, i8** %9
%12 = bitcast i8* %11 to i8**
store i8** %12, i8*** %10
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %4
%16 = load i8**, i8*** %10
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = call i8* @strdup(i8* %20)
%22 = load i8**, i8*** %10
store i8* %21, i8** %22
store i32 0, i32* %5
br label %35
23: ; preds = %15, %4
%24 = load i8**, i8*** %10
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = call i8* @strdup(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%31 = load i8**, i8*** %10
store i8* %30, i8** %31
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %32, i8* %33)
store i32 0, i32* %5
br label %35
35: ; preds = %29, %19
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"TOO MANY\00"
@.str.2 = [8 x i8] c"%s. %s\0A\00"
@str = [35 x i8] c"Found more than one matching item:\00"
define i32 @task_find_one(i8* %0, i8* %1, i32 %2, i8* nocapture %3) {
%5 = bitcast i8* %3 to i8**
%6 = icmp eq i32 %2, 0
%7 = load i8*, i8** %5
%8 = icmp eq i8* %7, null
br i1 %6, label %12, label %9
9: ; preds = %4
br i1 %8, label %10, label %15
10: ; preds = %9
%11 = tail call i8* @strdup(i8* %0)
store i8* %11, i8** %5
br label %18
12: ; preds = %4
br i1 %8, label %13, label %15
13: ; preds = %12
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %9, %13, %12
%16 = tail call dereferenceable_or_null(9) i8* @strdup(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %5
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
br label %18
18: ; preds = %15, %10
ret i32 0
}