#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*/ bzero(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
scalar_t__ strstr(char *, char *);
char *extract_var(char *vars, char *name) {
  static char temp[256];
  char *pos, *end;
  int length;
  sprintf(temp, "%s=", name);
  pos = (char *)strstr(vars, temp);
  if (!pos)
    return 0;
  pos += strlen(name) + 1;
  length = 0;
  for (end = pos; *end != 0 && *end != '&'; end++)
    length++;
  bzero(temp, 256 - 1);
  if (length >= 256)
    length = 256 - 1;
  strncpy(temp, pos, length);
  return (char *)temp;
}


x86 assembly (clang, -O0):
<extract_var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
lea    0x2ef5(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0x2ede(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a3 <extract_var+0x53>
movq   $0x0,-0x8(%rbp)
jmp    1259 <extract_var+0x109>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2d(%rbp)
je     11ec <extract_var+0x9c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11fc <extract_var+0xac>
jmp    1216 <extract_var+0xc6>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c7 <extract_var+0x77>
lea    0x2e43(%rip),%rdi
mov    $0xff,%esi
call   1050 <bzero@plt>
cmpl   $0x100,-0x2c(%rbp)
jl     123b <extract_var+0xeb>
movl   $0xff,-0x2c(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0x2e17(%rip),%rdi
call   1030 <strncpy@plt>
lea    0x2e0b(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_var>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x2efc(%rip),%r14
lea    0xe95(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11df <extract_var+0x8f>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%eax
test   %al,%al
je     11b2 <extract_var+0x62>
cmp    $0x26,%al
je     11b2 <extract_var+0x62>
add    $0x1,%rbp
jmp    11a0 <extract_var+0x50>
mov    $0xff,%r15d
mov    %r14,%rdi
mov    $0xff,%esi
call   1050 <bzero@plt>
cmp    $0xff,%ebp
cmovb  %ebp,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
jmp    11e2 <extract_var+0x92>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@extract_var.temp = internal global [256 x i8] zeroinitializer
@.str = [4 x i8] c"%s=\00"
define i8* @extract_var(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %4
%12 = call i64 @strstr(i8* %11, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0))
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
store i8* null, i8** %3
br label %51
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %19, 1
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 %20
store i8* %22, i8** %6
store i32 0, i32* %8
%23 = load i8*, i8** %6
store i8* %23, i8** %7
br label %24
24: ; preds = %39, %17
%25 = load i8*, i8** %7
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i8*, i8** %7
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 38
br label %34
34: ; preds = %29, %24
%35 = phi i1 [ false, %24 ], [ %33, %29 ]
br i1 %35, label %36, label %42
36: ; preds = %34
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %39
39: ; preds = %36
%40 = load i8*, i8** %7
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %7
br label %24
42: ; preds = %34
%43 = call i32 @bzero(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0), i32 255)
%44 = load i32, i32* %8
%45 = icmp sge i32 %44, 256
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 255, i32* %8
br label %47
47: ; preds = %46, %42
%48 = load i8*, i8** %6
%49 = load i32, i32* %8
%50 = call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0), i8* %48, i32 %49)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0), i8** %3
br label %51
51: ; preds = %47, %16
%52 = load i8*, i8** %3
ret i8* %52
}

LLVM IR (-O2):
@extract_var.temp = internal global [256 x i8] zeroinitializer
@.str = [4 x i8] c"%s=\00"
define i8* @extract_var(i8* %0, i8* %1) {
%3 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%4 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = inttoptr i64 %4 to i8*
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = add nsw i64 %8, 1
%10 = getelementptr inbounds i8, i8* %7, i64 %9
br label %11
11: ; preds = %15, %6
%12 = phi i8* [ %10, %6 ], [ %17, %15 ]
%13 = phi i32 [ 0, %6 ], [ %16, %15 ]
%14 = load i8, i8* %12
switch i8 %14, label %15 [
i8 0, label %18
i8 38, label %18
]
15: ; preds = %11
%16 = add nuw nsw i32 %13, 1
%17 = getelementptr inbounds i8, i8* %12, i64 1
br label %11
18: ; preds = %11, %11
%19 = tail call i32 @bzero(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0), i32 255)
%20 = icmp ult i32 %13, 255
%21 = select i1 %20, i32 %13, i32 255
%22 = tail call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0), i8* %10, i32 %21)
br label %23
23: ; preds = %2, %18
%24 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @extract_var.temp, i64 0, i64 0), %18 ], [ null, %2 ]
ret i8* %24
}