#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 */
struct MIMEItem {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ lookup(struct MIMEItem **, char const *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
char *strrchr(char const *, char);
void set_extension(struct MIMEItem **et, const char *filepath,
                   char *content_type) {
  const char *dot = strrchr(filepath, '.');
  if (!dot) {
    sprintf(content_type, "text/plain");
  } else {
    strncpy(content_type, lookup(et, dot + 1), 100);
  }
}


x86 assembly (clang, -O0):
<set_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <set_extension+0x46>
mov    -0x18(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11af <set_extension+0x6f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1050 <lookup@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    $0x64,%edx
call   1030 <strncpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_extension>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1171 <set_extension+0x41>
add    $0x1,%rax
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <lookup@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x64,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strncpy@plt>
movabs $0x616c702f74786574,%rax
70 6c 61
mov    %rax,(%rbx)
movl   $0x6e6961,0x7(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.MIMEItem = type { i32 }
@.str = [11 x i8] c"text/plain\00"
define void @set_extension(%struct.MIMEItem** %0, i8* %1, i8* %2) {
%4 = alloca %struct.MIMEItem**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store %struct.MIMEItem** %0, %struct.MIMEItem*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %5
%9 = call i8* @strrchr(i8* %8, i8 signext 46)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %22
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = load %struct.MIMEItem**, %struct.MIMEItem*** %4
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i32 @lookup(%struct.MIMEItem** %17, i8* %19)
%21 = call i32 @strncpy(i8* %16, i32 %20, i32 100)
br label %22
22: ; preds = %15, %12
ret void
}

LLVM IR (-O2):
%struct.MIMEItem = type { i32 }
@.str = [11 x i8] c"text/plain\00"
define void @set_extension(%struct.MIMEItem** %0, i8* %1, i8* %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %3
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(11) %2, i8* align 1 dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 11, i1 false)
br label %11
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %4, i64 1
%9 = tail call i32 @lookup(%struct.MIMEItem** %0, i8* %8)
%10 = tail call i32 @strncpy(i8* %2, i32 %9, i32 100)
br label %11
11: ; preds = %7, %6
ret void
}