#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 */
scalar_t__ strcmp(char const *, char const *);
int set_type(const char *type, char **envname) {
  const char *types[] = {"exec", "man", NULL};
  char *envs[] = {"PATH", "MANPATH", NULL};
  size_t i = -1;
  while (types[++i]) {
    if (strcmp(types[i], type) == 0) {
      *envname = envs[i];
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<set_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2cb9(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cb6(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2cb3(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cb8(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2cb5(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2cb2(%rip),%rax
mov    %rax,-0x40(%rbp)
movq   $0xffffffffffffffff,-0x58(%rbp)
ff
mov    -0x58(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x58(%rbp)
cmpq   $0x0,-0x28(%rbp,%rax,8)
je     11c2 <set_type+0xb2>
mov    -0x58(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11bd <set_type+0xad>
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11c9 <set_type+0xb9>
jmp    116a <set_type+0x5a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_type>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xedf(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
je     1151 <set_type+0x41>
lea    0xece(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1161 <set_type+0x51>
mov    $0x1,%ecx
lea    0x2ca8(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"exec\00"
@.str.1 = [4 x i8] c"man\00"
@__const.set_type.types = [3 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [5 x i8] c"PATH\00"
@.str.3 = [8 x i8] c"MANPATH\00"
@__const.set_type.envs = [3 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8* null]
define i32 @set_type(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca [3 x i8*]
%7 = alloca [3 x i8*]
%8 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
%9 = bitcast [3 x i8*]* %6 to i8*
%10 = bitcast [3 x i8*]* %7 to i8*
store i64 -1, i64* %8
br label %11
11: ; preds = %29, %2
%12 = load i64, i64* %8
%13 = add i64 %12, 1
store i64 %13, i64* %8
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %30
17: ; preds = %11
%18 = load i64, i64* %8
%19 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = load i8*, i8** %4
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i64, i64* %8
%26 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 %25
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
store i8* %27, i8** %28
store i32 0, i32* %3
br label %31
29: ; preds = %17
br label %11
30: ; preds = %11
store i32 1, i32* %3
br label %31
31: ; preds = %30, %24
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [5 x i8] c"exec\00"
@.str.1 = [4 x i8] c"man\00"
@.str.2 = [5 x i8] c"PATH\00"
@.str.3 = [8 x i8] c"MANPATH\00"
@__const.set_type.envs = [3 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8* null]
define i32 @set_type(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5, %2
%9 = phi i64 [ 0, %2 ], [ 1, %5 ]
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.set_type.envs, i64 0, i64 %9
%11 = load i8*, i8** %10
store i8* %11, i8** %1
br label %12
12: ; preds = %5, %8
%13 = phi i32 [ 0, %8 ], [ 1, %5 ]
ret i32 %13
}