#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__ isprint(int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
void popt(int key, char *arg) {
  char buf[10];
  if (isprint(key))
    sprintf(buf, "%c", key);
  else
    sprintf(buf, "%d", key);
  if (arg)
    printf("KEY %s: %s\n", buf, arg);
  else
    printf("KEY %s\n", buf);
}


x86 assembly (clang, -O0):
<popt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1169 <popt+0x39>
lea    -0x1a(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea1(%rip),%rsi
call   1050 <sprintf@plt>
jmp    117c <popt+0x4c>
lea    -0x1a(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe8c(%rip),%rsi
call   1050 <sprintf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11a2 <popt+0x72>
lea    -0x1a(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b4 <popt+0x84>
lea    -0x1a(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<popt>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
call   1040 <isprint@plt>
test   %rax,%rax
je     116c <popt+0x3c>
mov    %bpl,0xe(%rsp)
movb   $0x0,0xf(%rsp)
test   %rbx,%rbx
je     1184 <popt+0x54>
lea    0xea8(%rip),%rdi
lea    0xe(%rsp),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1197 <popt+0x67>
lea    0xe8d(%rip),%rsi
lea    0xe(%rsp),%rdi
mov    %ebp,%edx
call   1050 <sprintf@plt>
test   %rbx,%rbx
jne    1154 <popt+0x24>
lea    0xe84(%rip),%rdi
lea    0xe(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"KEY %s: %s\0A\00"
@.str.3 = [8 x i8] c"KEY %s\0A\00"
define void @popt(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [10 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = call i64 @isprint(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* %3
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %17
13: ; preds = %2
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* %3
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %9
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%22 = load i8*, i8** %4
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %22)
br label %27
24: ; preds = %17
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %20
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"KEY %s: %s\0A\00"
@.str.3 = [8 x i8] c"KEY %s\0A\00"
define void @popt(i32 %0, i8* %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @isprint(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = trunc i32 %0 to i8
store i8 %8, i8* %4
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
store i8 0, i8* %9
br label %12
10: ; preds = %2
%11 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %12
12: ; preds = %10, %7
%13 = icmp eq i8* %1, null
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %1)
br label %18
16: ; preds = %12
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %18
18: ; preds = %16, %14
ret void
}