#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*/ assert_log(int, int, char *, int *);
int /*<<< orphan*/ strcmp(char *, char *);
char *upto_char(char *, char);
int test_upto_char(int verbose) {
  int ok = 1;
  char *line = "this is a line # this is a comment";
  char *rm = upto_char(line, '#');
  assert_log(!strcmp(rm, "this is a line "), verbose, "! upto_char", &ok);
  line = "this is a line # this is a comment";
  rm = upto_char(line, '-');
  assert_log(!strcmp(rm, line), verbose, "! upto_char 2", &ok);
  return ok;
}


x86 assembly (clang, -O0):
<test_upto_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xeb7(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x23,%esi
call   1030 <upto_char@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xead(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1050 <assert_log@plt>
lea    0xe6a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2d,%esi
call   1030 <upto_char@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
mov    -0x4(%rbp),%esi
lea    0xe6f(%rip),%rdx
lea    -0x8(%rbp),%rcx
call   1050 <assert_log@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_upto_char>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
lea    0xeb6(%rip),%r14
mov    %r14,%rdi
mov    $0x23,%esi
call   1030 <upto_char@plt>
lea    0xec5(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
lea    0xebe(%rip),%rdx
lea    0xc(%rsp),%r15
mov    %ebx,%esi
mov    %r15,%rcx
call   1050 <assert_log@plt>
mov    %r14,%rdi
mov    $0x2d,%esi
call   1030 <upto_char@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
lea    0xe94(%rip),%rdx
mov    %ebx,%esi
mov    %r15,%rcx
call   1050 <assert_log@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [35 x i8] c"this is a line # this is a comment\00"
@.str.1 = [16 x i8] c"this is a line \00"
@.str.2 = [12 x i8] c"! upto_char\00"
@.str.3 = [14 x i8] c"! upto_char 2\00"
define i32 @test_upto_char(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %2
store i32 1, i32* %3
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = load i8*, i8** %4
%7 = call i8* @upto_char(i8* %6, i8 signext 35)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strcmp(i8* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
%13 = load i32, i32* %2
%14 = call i32 @assert_log(i32 %12, i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %3)
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8** %4
%15 = load i8*, i8** %4
%16 = call i8* @upto_char(i8* %15, i8 signext 45)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = load i8*, i8** %4
%19 = call i32 @strcmp(i8* %17, i8* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
%22 = zext i1 %21 to i32
%23 = load i32, i32* %2
%24 = call i32 @assert_log(i32 %22, i32 %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [35 x i8] c"this is a line # this is a comment\00"
@.str.1 = [16 x i8] c"this is a line \00"
@.str.2 = [12 x i8] c"! upto_char\00"
@.str.3 = [14 x i8] c"! upto_char 2\00"
define i32 @test_upto_char(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = tail call i8* @upto_char(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext 35)
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert_log(i32 %7, i32 %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%9 = call i8* @upto_char(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext 45)
%10 = call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(35) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert_log(i32 %12, i32 %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
ret i32 %14
}