#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *,
                           char const *);
scalar_t__ strlen(char const *);
void log_choice(FILE *fp, const char *name, unsigned num, const char *choices) {
  unsigned i;
  for (i = 0; *choices; i++) {
    if (i == num) {
      fprintf(fp, "%s = %s\n", name, choices);
      return;
    }
    choices += strlen(choices) + 1;
  }
}


x86 assembly (clang, -O0):
<log_choice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1197 <log_choice+0x77>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1174 <log_choice+0x54>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe96(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1197 <log_choice+0x77>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113e <log_choice+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_choice>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rcx)
je     1159 <log_choice+0x39>
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
add    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
je     1164 <log_choice+0x44>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmpb   $0x0,0x1(%rax,%rbx,1)
lea    0x1(%rax,%rbx,1),%rbx
jne    1140 <log_choice+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe95(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

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

LLVM IR (-O2):
@.str = [9 x i8] c"%s = %s\0A\00"
define void @log_choice(i32* nocapture %0, i8* %1, i32 %2, i8* %3) {
%5 = load i8, i8* %3
%6 = icmp eq i8 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %4, %13
%8 = phi i32 [ %17, %13 ], [ 0, %4 ]
%9 = phi i8* [ %16, %13 ], [ %3, %4 ]
%10 = icmp eq i32 %8, %2
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %9)
br label %20
13: ; preds = %7
%14 = tail call i64 @strlen(i8* %9)
%15 = add nsw i64 %14, 1
%16 = getelementptr inbounds i8, i8* %9, i64 %15
%17 = add i32 %8, 1
%18 = load i8, i8* %16
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %7
20: ; preds = %13, %4, %11
ret void
}